Crusader Posted December 21, 2006 Share Posted December 21, 2006 [code]Array( [0] => Array ( [sector] => 18 [owner] => 1 [ship] => 4 [mothership] => carrier [name] => scout 1 ) [1] => Array ( [sector] => 39 [owner] => 1 [ship] => 3 [mothership] => carrier [name] => fighter 2 ) [2] => Array ( [sector] => 39 [owner] => 1 [ship] => 3 [mothership] => carrier [name] => fighter 1 ) [3] => Array ( [sector] => 40 [owner] => 1 [ship] => 3 [mothership] => carrier [name] => fighter 3 ) [4] => Array ( [sector] => 40 [owner] => 2 [ship] => 3 [mothership] => carrier 2 [name] => fighter 2 ) [5] => Array ( [sector] => 40 [owner] => 2 [ship] => 3 [mothership] => carrier 2 [name] => fighter 3 ))[/code]How would I filter through this and get only the arrays with sector equalling zero? I've been trying array_filter filter but I'm having a hard time figuring it out since you have to do something like $variable[0]['sector'] to get a value. Link to comment https://forums.phpfreaks.com/topic/31446-get-specific-values-in-multidimensional-array/ Share on other sites More sharing options...
kenrbnsn Posted December 21, 2006 Share Posted December 21, 2006 Try something like this (untested):[code]<?php$new_array = array();for ($i=0;$i<count($orig);$i++) if ($orig[$i]['sector'] == 0) $new_array[] = $orig[$i];echo '<pre>' . print_r($new_array,true) . '</pre>';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/31446-get-specific-values-in-multidimensional-array/#findComment-145650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.