Hi,
I can't seem to use in_array or array_search to match part of a string in my multidimensional array:
$array['cart]['key1'] = "Test string1 of 1"
['key2'] = "Test string2 of 2"
..
I want to search this array for "string2" and get the key associated with this value. Does anyone have a code for that DOES NOT use "foreach" or any other looping through array method?
Thanks!
How to match value in multidimensional array?
Moderator: General Moderators
-
crimsontwo
- Forum Newbie
- Posts: 6
- Joined: Fri Apr 16, 2010 3:41 pm
Re: How to match value in multidimensional array?
If everything to search through is in $array["cart"] then
Code: Select all
array_search("string2", $array["cart"])-
crimsontwo
- Forum Newbie
- Posts: 6
- Joined: Fri Apr 16, 2010 3:41 pm
Re: How to match value in multidimensional array?
doesn't work because everything is in $array["cart"][???]
Re: How to match value in multidimensional array?
Oh, part of a string. Missed that.
Then no. There is no built-in function to do that. You'll have to write some code somewhere to do it: either a function or a loop.
Then no. There is no built-in function to do that. You'll have to write some code somewhere to do it: either a function or a loop.
Re: How to match value in multidimensional array?
Pretty easy. foreach() loop using if(strpbrk())crimsontwo wrote: I want to search this array for "string2" and get the key associated with this value.
Illogical statements are impossible... even in_array or search_array loop through the array.crimsontwo wrote:Does anyone have a code for that DOES NOT use "foreach" or any other looping through array method?