note 30385 deleted from function.array-search by levim

From: Date: Mon, 24 Feb 2014 22:36:43 +0000
Subject: note 30385 deleted from function.array-search by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198641@lists.php.net to get a copy of this message
Note Submitter: Darkvie ---- I wanted to search a multidimensional array for a value & assign another element of array CONTAINING the searched value. In the array I am using ($Projects), each item in $Projects contains a "Text_ID" & "Text_Value" field from a database result. I want to search for a "Text_ID" value (456 in this example) & get it's "Text_Value" value assigned to a variable called $Text_Value. Here's how I did it: ============================================ <?PHP //Array I am going to look in: $Projects[0] = array(123, "Text 1"); $Projects[1] = array(456, "Text 2"); $Projects[2] = array(789, "Text 3"); // This loop goes through every element in $Projects foreach ($Projects as $key => $ArrayRow) { // Now: $ArrayRow[0] = $Projects[x][0] and $ArrayRow[1] = $Projects[x][1] // Look for the value "456". Assign to variable & stop looking if found. if ($ArrayRow[0] == "456") {$Text_Value= $ArrayRow[1]; break; } } ?> ============================================ Hope this helps someone. -Darkive

« previous php.notes (#198641) next »