php - array search not working -
php - array search not working -
i have got folowing code.
$coauthors = get_post_meta( $post_id, "coauthors" ); print_r($coauthors);
ok result print_r is
array ( [0] => 78 ) array ( [0] => 78 )
now user id 78 should homecoming true follow code doesnt.
$key = array_search( 78, $coauthors ); if($key) { homecoming true; }else{ echo "no"; }
why no going wrong best way this???
thanks
im still getting issues here function. add_action('is_true','isdauthortrue'); function isdauthortrue( $post_id ) { $current_user = wp_get_current_user(); if ( !($current_user instanceof wp_user) ) return; $current_user = wp_get_current_user(); $coauthors = get_post_meta( $post_id, "coauthors" ); $key = array_search( $current_user->id, $coauthors ); $key = 0; if($key !== false) { homecoming true; } else { homecoming false; } }
and trying run in loop.
if(do_action( 'is_true', $post->id )){ echo "yes"; }else{ echo "no"; }
help???
$key = 0;
that results in false.
you should check key this:
if($key !== false) { // sth } else { // not exist }
php arrays wordpress
Comments
Post a Comment