Thursday, 15 January 2015

mysql - How to get unique ids from array loop using php -



mysql - How to get unique ids from array loop using php -

i have next array getting mysql result set

array ( [0] => array ( [slug] => block_three_column [title] => csg 2 [type_id] => 8 [entry_id] => 6 [stream_id] => 11 ) [1] => array ( [slug] => block_three_column [title] => csg [type_id] => 8 [entry_id] => 5 [stream_id] => 11 ) ) array ( [0] => array ( [slug] => block_three_column [title] => csg 2 [type_id] => 8 [entry_id] => 6 [stream_id] => 11 ) [1] => array ( [slug] => block_three_column [title] => csg [type_id] => 8 [entry_id] => 5 [stream_id] => 11 ) )

the both arrays similar want unique entry id using php.

i tried next code producing 2 arrays again.

foreach($block_results $rowarr) { foreach($rowarr $k=>$v) { if($k == "entry_id") { $entid[] = $v; } } }

any help highly appreciated. in advance.

you can entry_id directly:

$array = array( array( 'slug' => 'block_three_column', 'title' => 'csg 2', 'type_id' => 8, 'entry_id' => 6, 'stream_id' => 11 ), array( 'slug' => 'block_three_column', 'title' => 'csg', 'type_id' => 8, 'entry_id' => 5, 'stream_id' => 11 ) ); foreach ($array $innerarray) { if (isset($innerarray['entry_id'])) { $entid[] = $innerarray['entry_id']; } } var_dump($entid);

output is:

array 0 => int 6 1 => int 5

php mysql arrays

No comments:

Post a Comment