php - Find num value in array keys -


//i have array that:

$roms = array (  [1] => 2 [2] => 4 [6] => 2     [7] => 7  ) 

//i have data table bellow:

id               room             total_room  1                 1b/1b             7  2                 2b/2b             12  6                 3b/ 2b            32  8                 3b/3b             7 

//when query result

$total_rooms   = 0 ;  foreach( $query->result() $row )  {      if  ( $row->id , array_keys($rooms) ) :         $total_rooms[] = array_values( $rooms ); // array values     else:         $total_rooms[] = $row->total_room;  // table     endif;  } 

//i want result that:

$total_rooms = 2; // array value $total_rooms = 4; // array value $total_rooms = 2; // array value $total_rooms = 7; // not array value : becos no id in keys 

but code not work me!

can me?

your if statement , following line little weird, try this:

if(array_key_exists($row->id, $rooms)) :     $total_rooms[] = $rooms[$row->id]; // array else:     $total_rooms[] = $row->total_room;  // table endif; 

note: assigning new array key $total_rooms each time, sure don't want regular old variable? see:

$total_rooms = $rooms[$row->id]; // array 

array_key_exists() manual


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -