I a code like this
for($ctr=0; $ctr < 4; $ctr++) {
$messages["message"] = $ctr;
array_push($response["messages"], $messages);
}
I want to get the message
that contains the value 2
. How do I do that in PHP?
I a code like this
for($ctr=0; $ctr < 4; $ctr++) {
$messages["message"] = $ctr;
array_push($response["messages"], $messages);
}
I want to get the message
that contains the value 2
. How do I do that in PHP?
you have to use array search on this case.
for($ctr=0; $ctr < 4; $ctr++) {
//$messages["message"] = $ctr;
array_push($response, $ctr);
}
echo array_search('2', $response);
array search give you the index of the array which value is 2.