Jump to content

Recommended Posts

Hi,

 

I have an array like this one:

Array ( [0] => stdClass Object ( [id_distrito] => 01 ) [1] => stdClass Object ( [id_distrito] => 04 ) [2] => stdClass Object ( [id_distrito] => 11 ) [3] => stdClass Object ( [id_distrito] => 13 ) ) 

 

How can I know if for example the value '11' is inside this array?

 

Best Regards,

The print out does not show an array containing arrays, but rather an array containing objects.  There are lots of ways to do what you want, but a simple one would be:

 

data = array(
(object) array('id_distrito' => '01'),
(object) array('id_distrito' => '04'),
(object) array('id_distrito' => '11'),
(object) array('id_distrito' => '13'),
);

$contains = FALSE;
foreach ($data as $object) {
if ($object->id_distrito === '11') {
	$contains = TRUE;
	break;
}
}

 

If $contains is true after that, the array contains an object with id 11.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.