0

So this is getting on my nerves right now
I have an associative array that I populate from another array:

foreach ($possible_unavailable as $p) {
    $aux[] = array('date' => $p['date'], 'status' => -1);
}
var_dump($aux);

And then I do the following:

foreach ($aux as $pu) {
   var_dump($pu['date']);
   var_dump(array_search($pu['date'], $aux));
}

This is the output:

array(2) {
  [0]=>
  array(2) {
    ["date"]=>
    string(10) "2014-09-01"
    ["status"]=>
    int(-1)
  }
  [1]=>
  array(2) {
    ["date"]=>
    string(10) "2014-09-05"
    ["status"]=>
    int(-1)
  }
}
string(10) "2014-09-01"
bool(false)
string(10) "2014-09-05"
bool(false)


Why "array_search($pu['date'], $aux)" is not returning true?

5
  • 2
    possible duplicate of Search_array in nested arrays Commented Aug 15, 2014 at 0:49
  • my array is not multi dimensional, its just an associative array that has string values. Commented Aug 15, 2014 at 0:51
  • @dan yes it is, it's an array of arrays Commented Aug 15, 2014 at 0:59
  • You have one nested array of several associative arrays. Commented Aug 15, 2014 at 1:00
  • Yes but what I meant is that I dont have something like this: array("date" => array("2014-09-01", "2014-09-02") , "status" => -1), as the possible duplicate post. Commented Aug 15, 2014 at 1:13

1 Answer 1

1

If I understood well, you are trying to search a string in an array filled with arrays, so the array_search is comparing an string with an array like this:

is "2014-09-01" equals to array("date" => "2014-09-01", "status" => -1) ??

Obviously the return value is false.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you... I misunderstood the array_search function and got a little bit confused. This solved it: array_search($pu['date'], $pu)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.