note 106107 added to function.array-search

From: Date: Tue, 11 Oct 2011 11:12:37 +0000
Subject: note 106107 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-183779@lists.php.net to get a copy of this message
Better solution of multidimensional searching. function multidimensional_search($parents, $searched) { if (empty($searched) || empty($parents)) { return false; } foreach ($parents as $key => $value) { $exists = true; foreach ($searched as $skey => $svalue) { $exists = ($exists && IsSet($parents[$key][$skey]) && $parents[$key][$skey] == $svalue); } if($exists){ return $key; } } return false; } $parents = array(); $parents[] = array('date'=>1320883200, 'uid'=>3); $parents[] = array('date'=>1320883200, 'uid'=>5); $parents[] = array('date'=>1318204800, 'uid'=>5); echo multidimensional_search($parents, array('date'=>1320883200, 'uid'=>5)); // 1 ---- Server IP: 69.147.83.197 Probable Submitter: 94.74.229.98 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/106107 Del: integrated -- https://master.php.net/note/delete/106107/integrated Del: useless -- https://master.php.net/note/delete/106107/useless Del: bad code -- https://master.php.net/note/delete/106107/bad+code Del: spam -- https://master.php.net/note/delete/106107/spam Del: non-english -- https://master.php.net/note/delete/106107/non-english Del: in docs -- https://master.php.net/note/delete/106107/in+docs Del: other reasons-- https://master.php.net/note/delete/106107 Reject -- https://master.php.net/note/reject/106107 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183779) next »