Generate json to php find ID value through php [duplicate] - php

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
Find ID value through php
stdClass Object ( [Providers] => Array (
[0] => stdClass Object (
[Main_Fax] =>
[Signed_POA] => No
[Signed_HIPAA] => No
[Website] => www.google.com
[VAR_Provider_Type] => Template Test
[State_Temp] =>
[City] =>
[Notes] =>
[Main_Phone] =>
[ZIP] =>
[Provider_Type_Temp] =>
[State] => Alaska
[Signed_Purchae_Agreement] => No
[Reimbursement_Rate] => 0
[ID] => 977948000009029003
[Provider_Name] => Amit
[Address_Line_1] =>
[In_Network] => No
[Address_Line_2] =>
)
)
)
Seprate this json & show id value through php -> means this value [ID] => 977948000009029003

Let your array is $arr.
Now try this:
$arr->Providers[0]->ID;
Result:
977948000009029003

$data->Providers[0]->ID
See the structure of the object you gave us. You can see there's an object with a item called Providers. You can then see that the value of "Providers" is an array indexed by a integer, which inside it has an Object. The object contains the ID you wish to obtain.
Object > Array > Object

Related

php array get single value [duplicate]

This question already has answers here:
How to get single value from this multi-dimensional PHP array [duplicate]
(6 answers)
Closed 5 years ago.
I have an array:
print_r($response);
will show:
Response: Array
(
[errors] => false
[return] => Array
(
[price_recurring] => 0
[country_code] => NL
[invoicemethod] => instant
[product_id] => 0
[affiliate] =>
[number_of_periods] => 1
[description] => Betaling voor eventid 274
[period_duration] => 1 month
[date] => 29/11/2017 19:42
[order_quantity] => 1
[vat] => 21
[amount_total] => 4599
[total_paused_days] => 0
[custom] => WEB1511980957x194237
[emailaddress] => ik#ik.nl
[amount_affiliate_initial] => 0
[total] => 45,99
[current_status] => completed
[amount_affiliate_recurring] => 0
[amount_total_affiliate] => 0
[id] => 1790226
[price_initial] => 4599
[current_number_of_periods] => 1
[firstname] =>
)
)
How can i extract the value 'custom'?
I've tried:
$response = array_shift($response);
echo $response['custom'];
but it will show nothing. What am i doing wrong here? I know i am close.
$response is an array with two keys errors and return. $response['return'] in turn, is an array with several keys, including custom. Therefore, to access custom, you need to reference $response['return']['custom']
you have an array inside an array
$response["return"]["custom"]
also try to var_dump (or print_r depends on what you prefer) instead of echoing when you try to navigate
var_dump( $response["custom"]);
would tell you a lot more than echoing null, which prints nothing

How can I access array's item when there is an object in it? [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 5 years ago.
I have an array like this:
echo "<pre>";
print_r($res_users);
/*
Array
(
[0] => stdClass Object
(
[position] => 1
[user] => stdClass Object
(
[full_name] => دکوراسیون
[is_private] => 1
[has_anonymous_profile_picture] =>
[byline] => 39.3k followers
[profile_pic_url] => https://scontent-frt3-1.cdninstagram.com/t51.2885-19/s150x150/11352072_817936521647202_201395223_a.jpg
[pk] => 1480272396
[follower_count] => 39326
[is_verified] =>
[mutual_followers_count] => 0
[username] => sajad.sobhi
)
)
)
All I'm trying to do is selecting following URL from array above:
https://scontent-frt3-1.cdninstagram.com/t51.2885-19/s150x150/11352072_817936521647202_201395223_a.jpg
Which is the value of profile_pic_url. How can I get that?
Noted that this doesn't work:
echo $res_users[0]['user']['profile_pic_url'];
Try $res_users[0]->user->profile_pic_url. Because $res_users[0] is object type
Try it by this way
echo $res_users[0]->user->profile_pic_url;

Can't echo array items [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
I have an array which I can't seem to access properly, been trying to echo the address. It's called $user and here is the print_r for it:
Array(
[0] => stdClass Object
(
[id] => 1
[firstname] => Casper
[lastname] => *lastname*
[email] => someEmail
[username] => aUsername
[password] => *encrypted password*
[address] => myAddress
[address2] =>
[city] =>
[state] =>
[zipcode] => 1111
[join_date] => current timestamp
)
)
1
It's in codeigniter and so far I've tried:
echo $user['address'];
echo $user->address;
Both of them with no luck. Any help is greatly appriciated
You have a multi-dimensional array and the first index is 0, also inside the first index you have the object. to access an array of object you need to use ->
You have to echo like given code:
echo $user[0]->address;

Access to a specific array in php [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
i create an array and i would like to access to the value but i really don't know how :
Here is my array :
Array
(
[0] => Array
(
[id] => 1
[id_orga] => 36094152
[nom] => Adresse externe
[url] => https://cubber.zendesk.com/api/v2/organizations/36094152.json
[created] => 2015-01-22 08:00:53
[updated] => 2015-01-22 08:00:53
[tickets] => Array
(
)
[monthly] => Array
(
[0] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[assist] => 0
[maint] => 0
[total] => 0
)
)
and i would like for example to access to the value "0" in the key "assist" and change it to "1" for example and i don't know how to do it.
Suppose the source array is called $myArray. Try:
$myArray[0]['monthly'][0]->storage['assist'] = 1
If that doesn't work, try:
$myArray[0]['monthly'][0]['storage']['assist'] = 1
Let me know which works so I delete the other.

How to read json out in php as a string? [duplicate]

This question already has an answer here:
how to decode this JSON string?
(1 answer)
Closed 8 years ago.
Respected All,
I have a string which I got from an api. Now I want to extract useful data from this string. This output is a result of Json query.
the string is
{"PR":{"Url":"http://www.ididthisfilm.com/lex_tmp2/custom-form/","Domain":"http://www.ididthisfilm.com","Title":"Lexicon Of Sustainability – Custom Form","Description":"Welcome to THE LIST EDIT FORM","Pictures":[{"Url":"http://www.ididthisfilm.com/lex_tmp2/wp-content/uploads/2014/05/Lexicon_logo_new_BETA.png","Alt":"Lexicon Of Sustainability","Title":"","SourceType":1,"Width":0,"Height":0,"ParsedAspectRatio":0}],"Videos":[],"AuthorName":null,"ExtraInfo":null},"EM":null}`
How can I get title and description and url in different variables so that I can use them in php.
use built-in function json_decode and you will get the JSON object.
$str=<<<CODE
{"PR":{"Url":"http://www.ididthisfilm.com/lex_tmp2/custom-form/","Domain":"http://www.ididthisfilm.com","Title":"Lexicon Of Sustainability - Custom Form","Description":"Welcome to THE LIST EDIT FORM","Pictures":[{"Url":"http://www.ididthisfilm.com/lex_tmp2/wp-content/uploads/2014/05/Lexicon_logo_new_BETA.png","Alt":"Lexicon Of Sustainability","Title":"","SourceType":1,"Width":0,"Height":0,"ParsedAspectRatio":0}],"Videos":[],"AuthorName":null,"ExtraInfo":null},"EM":null}
CODE;
print_r( json_decode($str) );
which outputs
stdClass Object
(
[PR] => stdClass Object
(
[Url] => http://www.ididthisfilm.com/lex_tmp2/custom-form/
[Domain] => http://www.ididthisfilm.com
[Title] => Lexicon Of Sustainability – Custom Form
[Description] => Welcome to THE LIST EDIT FORM
[Pictures] => Array
(
[0] => stdClass Object
(
[Url] => http://www.ididthisfilm.com/lex_tmp2/wp-content/uploads/2014/05/Lexicon_logo_new_BETA.png
[Alt] => Lexicon Of Sustainability
[Title] =>
[SourceType] => 1
[Width] => 0
[Height] => 0
[ParsedAspectRatio] => 0
)
)
[Videos] => Array
(
)
[AuthorName] =>
[ExtraInfo] =>
)
[EM] =>
)
if any error occurs, try this: json_last_error()

Categories