Please tell me how to output the imtId value, the array is not complete, I will not output further, but the meaning should be clear.Thank you in advance
Array
(
[id] => mavrin-wildberries-1635334576193516728
[jsonrpc] => 2.0
[result] => stdClass Object
(
[cards] => Array
(
[0] => stdClass Object
(
[id] => d3c33a3f-f5b3-5647-8e7a-ad50d27d4417
[imtId] => 30306963
[userId] => 0
[supplierId] => e9b901b9-b663-5648-97b8-6313d0e245ba
[imtSupplierId] => 0
I tried:
echo ['result']['cards'][0]['nmId']
A few things:
You need to echo an actual variable, not just a series of indexes.
The item inside "result" is an object, not an array
So is the item within the "0" index.
There is no such index as "nmld" - you said you wanted "imtId" instead, so I don't know why you didn't use that?
Therefore, if this data is contained in a variable called $arr then something like
echo $arr["result"]->cards[0]->imtId;
Related
I'm trying to access a piece of data in an array of arrays that (I believe) is in an object (this may not be the right term though).
When I do print_r on this: $order_total_modules->process() I get...
Array (
[0] => Array (
[code] => ot_subtotal
[title] => Sub-Total:
[text] => $49.99
[value] => 49.99
[sort_order] => 1
)
[1] => Array (
[code] => ot_total
[title] => Total:
[text] => $0.00
[value] => 0
[sort_order] => 12
)
)
If I run echo $order_total_modules->process()[1][3];, I should get "0", because that is the 3rd element of the 2nd array... right? Yet, I get an error.
Can anyone help with this?
Even though it is the third element counting from 0, the index is not 3 it is an associative array with the index value:
Available in PHP >=5.4.0:
echo $order_total_modules->process()[1]['value'];
Or PHP < 5.4.0:
$result = $order_total_modules->process();
echo $result[1]['value'];
You cannot access an associative array via an integer index(unless the index is an actial integer).
So in this case use :
[1]['code'] to access what woulde be [1][0] with a 'normal' array.
Try putting it in a var first:
$ar = $order_total_modules->process();
echo $ar[1]['value'];
The second level array is an assoc, which means that the key is not numeric, which means that you need to call the name of the key, hence the 'value'.
I have an array $presettings
print_r($presettings); outputs:
Array (
[0] => stdClass Object (
[uuid] => xxx-1ef8-aac6-xxx-xxx
[name] => etime
[owner] => eder112T Resident
[online] => 1
[channel] => 63b525ae-xxx-3555-1c74-xxx
[owner_uuid] => a371751c-eb77-xxx-899c-xxx
[simname] => Plainfield
[slurl] => xxx://xxx/xx/xx/243/24/xx/?title=xx
[design] => 2
[msg_oftheday] => two
[machine_name] => one
[autopay] =>
[autolog_leave] =>
[autolog_offline] =>
[allow_activation] =>
)
)
and now i want to get a special key:
echo "test output : "$presettings['machine_name']." testend";
outputs "" (nothing).
my method look like this
function preloadSettingsFromMYSQL($ownername,$prim_uuid)
{
$result = $this->instance->get_rows("SELECT * FROM etime_rims where owner='".$ownername."' AND uuid='".$prim_uuid."'");
return $result;
}
$result is an object array, also tried it with $presettings->machine_name, did not work too.
where is the error?
thank you.
If you look closely in the print_r result, you can see that there is a 0 there, meaning that those values aren't directly in $presettings, but actually in the first element of $presettings.
Just try:
$presettings[0]->machine_name
You object is multi dimensional so just add a level
$presettings[0]->machine_name;
As side note you have an object here and not array do don't try to access alues with scopes.
In your array, you have stdClass Object at index 0. You're looking to access the object's variables, which is a slightly different syntax than arrays:
echo $presettings[0]->machine_name;
I have an array of values returned from Facebook - let's call it $array.
If I do print_r($array) - it looks like this:
Array
(
[code] => 200
[headers] => Array
(
[0] => Array
(
[name] => Some value
[value] => *
)
[1] => Array
(
[name] => Some value
[value] => Some value
)
[2] => Array
(
[name] => Some value
[value] => Some value
)
)
[body] => {"about":"Some more values.","can_post":true}
)
I need to extract the body part from this array.
I cannot refer to it by it's position, I'm looking for something like $array->body and receive the {....} string.
$array->body would work if the variable $array was an object
For arrays, just use:
$body = $array['body'];
(see: http://be2.php.net/manual/en/language.types.array.php)
If you want to access to your array via -> just do 1 more step:
$array = (object) $array;
And now, you can access to your body via:
$array->body;
Else without this step there is just one way:
$array['body'];
If you are more interested about converting arrays into objects, you can visit this question: How to convert an array to object in PHP?
Access array elements by using their name.
$array['body'];
I get the following returned result from a print_r of a variable returned from a $metadataPlugin->metadata->listAction($filter, $pager) function. I am trying to echo out the [xml] piece but can't figure out how to do it.
KalturaMetadataListResponse Object ( [objects] => Array ( [0] => KalturaMetadata Object ( [id] => 1 [partnerId] => 8 [metadataProfileId] => 2 [metadataProfileVersion] => 1 [metadataObjectType] => 1 [objectId] => 0 [version] => 1 [createdAt] => 1353093894 [updatedAt] => 1353093894 [status] => 1 [xml] => 1353049200 ) ) [totalCount] => 1 )
I have tried
echo $result['objects'][0]->xml;
and
echo $result[0]->xml;
with no success.
It looks like it should be
$result->objects[0]->xml
Just remember when looking at print_r or var_dump results that any time you see Object (...) that you will need to use -> to access the property listed for that object.
So in this case, you have a base Object set as $result, which you then need to get the objects property from. That property contains an array. At index 0 of the array, is another Object, which is the Object where your xml property resides.
I have a multidim array that I can view using print_r($users):
Array
(
[0] => stdClass Object
(
[username] => crustacea
[created_on] => 2010-08-07 19:54:32
[active] => 1
)
)
I can also use print_r($users[0]). Since there's only one member in $users, the output looks somewhat the same.
I can't see how to retrieve the value crustacea. echo $users[0]['username']; doesn't do it. Examples I can find are echo $users['name_of_array']['username']; -- but I don't have a name of array to work with. How do I do it?
$user[0] is not an array but an object as indicated by [0] => stdClass Object.
echo $users[0]->username;
$user[0] is object and not an array. You can access your value by doing
$users[0]->username;
Or you could cast/convert your object into an array like
((array)$users[0])['username'];