Escape Null in array

Hi there, first post here. Looking for a bit of help with array in an array:

[php]stdClass::__set_state(array( ‘nid’ => ‘1’, ‘node_title’ => ‘A4E Ltd’, ‘node_type’ => ‘guide_organisation’, ‘node_vid’ => ‘173’, ‘node_data_field_members_field_members_uid’ => array ( 0 => array ( ‘uid’ => NULL, ), ), )) [/php]

This is the array and I am performing a count on that array but my code seems to be counting Null as a value
here is my code:
[php]<?php
if (!is_null($data->node_data_field_members_field_members_uid))
print count($data->node_data_field_members_field_members_uid);
?>[/php]

Can anyone tell me where I’m going wrong?

Hi,

I think array key “node_data_field_members_field_members_uid” will always return NULL since, from the code given, no value has been given to that key. Here’s the simplified version of your code:

[php]<?php
$second_arr= array ( 0 => array ( ‘uid’ => NULL), );
//stdClass::__set_state(
$arr=array(
‘nid’ => ‘1’,
‘node_title’ => ‘A4E Ltd’,
‘node_type’ => ‘guide_organisation’,
‘node_vid’ => ‘173’,
‘node_data_field_members_field_members_uid’ => $second_arr,
);
print_r($arr);
echo “
”;
?>[/php]

Here’s the output:

Array ( [nid] => 1 [node_title] => A4E Ltd [node_type] => guide_organisation [node_vid] => 173 [node_data_field_members_field_members_uid] => Array ( [0] => Array ( [uid] =>  ) ) ) 

By the way, I can’t seem to get the point why you needed to give an array as a value to an array key… Can you describe to us what you wanted to do in that portion? :slight_smile:

Happy to help,
CodeGuru

Hi, many thanks for your reply.

The first example returns 1 as the result of the count function.

example 2 returns 0

[php]stdClass::__set_state(array( ‘nid’ => ‘19’, ‘node_title’ => ‘CAN (Community Ability Network)’, ‘node_type’ => ‘guide_organisation’, ‘node_vid’ => ‘191’, ‘node_data_field_members_field_members_uid’ => array ( ), )) [/php]

What’s going on? Just has to be something to do with the NULL…

Anyone? This is driving me nuts >:(

Sponsor our Newsletter | Privacy Policy | Terms of Service