I have made a simple facebook register widget.
On register the App sends the data to send.php
On send.php I have
print_r($response);
And I get something like this:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1367953200
[issued_at] => 1367946138
[oauth_token] => BAAE0refKufgBAORkK7hUaVpF8MnFygoqHAHrO3nRJMyNjvJx6RjiMjoqbz2YlfqeogcIPGJJaIgD0xtxhBj1WRgQ5F5SidjwM7ZCKOyZBlEuatIqIccbjGj2uMV5hqtKtZA1g7hOEqMeZAEwmnO6SgRgsb9ittKZCDnPfoxYxCxZAZBAhIKX457IG5ZB4yknv9FZB8QUG7Pt0mfBRQUYG12KoTmO7QRH20LP65FyPqTi7mAZDZD
[registration] => Array
(
[name] => derp derp
[email] => ddddd#gmail.com
[location] => Array
(
[name] => Vienna, Austria
[id] => 1.1116511224109E+14
)
[gender] => male
[phone] => sss
)
[registration_metadata] => Array
(
[fields] => [ {'name':'name'}, {'name':'email'}, {'name':'location'}, {'name':'gender'}, {'name':'phone', 'description':'Phone Number', 'type':'text'},]
)
[user] => Array
(
[country] => at
[locale] => en_US
)
[user_id] => 100000506481284
)
So the data gets passed without a problem but how can I access a specific value?
For example text book array stuff doesnt appear to be working like:
print $response[0];
Gives me an error:
Notice: Undefined offset: 0 in C:\xampp\htdocs\ddd\send.php on line 38
How else can I access the data?
For example how could I store country, email, name or whatever in their own variables so I can echo them later? Its there but I cant seem to figure out how to "digest" it properly with php.
There is no index 0 in the array you pasted..
Use it like
$email = $response['registration']['email'];
If it was an object instead of an array you would do
$email = $response->registration->email
This is very basic PHP array handling.
http://php.net/manual/en/language.types.array.php
Related
Here i am having one multidimensional array , using this array i want to take from emails array i want to take user email value like abc#gmail.com and from name array i want to take value givenName like Raju and from image array i want to take url like www.domain.com
print_r($user_info);
Array
(
[kind] => plus#person
[etag] => "EhMivDE25UysA1M2v-A/ZXQsxHAN9QSz-hQoXfQGzFyLWdQ"
[gender] => male
[emails] => Array
(
[0] => Array
(
[value] => abc#gmail.com
[type] => account
)
)
[objectType] => person
[id] => 100776010499118027035
[displayName] => Raju r
[name] => Array
(
[familyName] => r
[givenName] => Raju
)
[url] => https://plus.google.com/100776010499118027035
[image] => Array
(
[url] => www.domain.com
[isDefault] =>
)
[isPlusUser] => 1
[language] => en
[circledByCount] => 1
[verified] =>
[domain] => www.facebook.com
)
Expected Results
abc#gmail.com
Raju
www.domain.com
I tried like this
foreach($user_info['emails'] as $result){
$user_email = $result['value'];
foreach($result['name'] as $nameresult){
$user_name = $nameresult['givenName'];
}
}
Seems name does not seems to be an array of arrays like emails. So you can directly take that name instead of inner loop
foreach($user_info['emails'] as $result){
$user_email = $result['value'];
}
In this it the email value will be overridden each time and will hold only last email element value.
&
$user_info['name']['familyName'];
$user_info['image']['url'];
What I understand from the above set of data is that a user will have multiple email ids and a one and one image url. So above logic works.
I got the following array as a result of an output from a web service? I printed the values in the array using the print_r() method as stated in the following description.
ARRAY OUTPUT:
Array
( [0] => stdClass Object
( [return] => stdClass Object
( [data] => stdClass Object
(
[status] => 50000
[adminUser] => 1
[atdUserid] => 58
[category] => [client] => [cur_designation] => TL
[currentEmpId] => E058
[digitPrefix] => 8,5,1,3,7,0
[email] => jaliya#codegen.net
[employeeId] => 58
[employee_status] => 1
[firstName] => Jaliya
[lastName] => Seneviratna
[last_login_date] => stdClass Object ( [date] => 6 [month] => 2 [year] => 2015 )
[letterPrefix] => D,C,U,T,Z,E
[loginName] => jaliya
[resourceStatus] =>
[taskPassword] => d6188c72995d80e1a8e00d34987e0f6b
[userId] => 118 )
[reason] => Success
[refetch] => 1
[status] => 1
) ) )
I got the above array by calling a webservice in php. I want to get the details out of this array. And the problem was that I couldn't get the stdClass objects casted into the right type. I tried the following code but it is not working. Can anyone help me to get the values inside the data[] out in php. I used the following code and it is not working and giving an exception.
CODE USED:
print_r(array_values($quote));
echo $quote[0]->data;
The exception was the following...
EXCEPTION RECIEVED:
Notice: Undefined property: stdClass::$data in C:\xampp\htdocs\WebServiceDemo-php\democlient.php on line 27
How to get values out from this array?
Please help me...
convert the object in to array using this function
get_object_vars(array);
USE Can Print each key value of data array like this:-
echo $quote[0]->data->status;
I will Print
50000
so heres my predicament.
Currently using Yahoo API with PHP in order to use a 'Login with Yahoo' Function on my site.
I have managed to retrieve my entire profile. Trouble is, I can't directly display the primary email associated with the account.
If I use print_r($profile) I get everything dumped from my profile. It looks like this (personal data removed):
stdClass Object ( [uri] => http://social.yahooapis.com/v1/user/*********/profile [guid] => ***** [birthdate] => / [created] => 2010-04-22T20:47:48Z [emails] => Array ( [0] => stdClass Object ( [handle] => **#gmail.com [id] => 1 [type] => HOME ) [1] => stdClass Object ( [handle] => ****#yahoo.com [id] => 2 [primary] => 1 [type] => HOME ) ) [familyName] => Surname [gender] => M [givenName] => Ricki [image] => stdClass Object ( [height] => 192 [imageUrl] => http://l.yimg.com/dh/ap/social/profile/profile_b192.png [size] => 192x192 [width] => 192 ) [lang] => en-US [memberSince] => 2010-04-08T11:22:56Z [nickname] => Ricki [profileUrl] => http://profile.yahoo.com/*********** [updated] => 2013-03-03T18:12:22Z [isConnected] => )
Using $profile->emails->handle yields nothing however. Any ideas on what to do? I can use $profile->emails which returns an Array, displayed simply as 'Array' but if i try to select from the array i get an error:
"Catchable fatal error: Object of class stdClass could not be converted to string"
Anyone?
$profile->emails[0]->handle will give you the first handle in the system.
You can also do foreach($profile->emails as $email) { print $email->handle; }
I am trying to create a facebook signup. I am receiving the signed_request from facebook that is being decoded and displayed as the following:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 0
[issued_at] => **********
[oauth_token] => *******************************************************************************************************************
[registration] => Array
(
[name] => Darren West
[email] => dwest#madeup.com
[password] => IJ8sU10lw
)
[registration_metadata] => Array
(
[fields] => name,email,password
)
[user] => Array
(
[country] => us
[locale] => en_US
)
[user_id] => ***************
)
I want to add the three fields within the registration array to a hidden form and automatically submit it to another page for saving to the database.
My question is how do I extract the name, email, and password from the registration array and assign them to individual variables. I used the following, but I don't get a result:
print $response['registration']->password;
Any help would be greatly appreciated.
Many thanks,
neojakey
print $response['registration']['password'];
I have an file uploading site, it has an option of uploading through urls, what I am trying to do is whenever a user uploads through url, I check my database if a file exists that was uploaded through same url it displays the download url directly instead of uploading it again.
The data sent to uploading script is in array form like:
Array (
[0] => http://i41.tinypic.com/3342r93.jpg
[1] => http://i41.tinypic.com/28cfub7.jpg
[2] => http://i41.tinypic.com/12dsa32.jpg
)
and the array used for outputing the results is in form like this:
Array
(
[0] => Array
(
[id] => 43
[name] => 3342r93.jpg
[size] => 362750
[descr] =>
[password] =>
[delete_id] => 75CE
[upload_id] => 75F45CAE1
)
[1] => Array
(
[id] => 44
[name] => 28cfub7.jpg
[size] => 105544
[descr] =>
[password] =>
[delete_id] => D392
[upload_id] => 6676FD881
)
[2] => Array
(
[id] => 45
[name] => 12dsa32.jpg
[size] => 49000
[descr] =>
[password] =>
[delete_id] => 54C9
[upload_id] => A58614C01
)
)
Now I want is that if the link http://i41.tinypic.com/28cfub7.jpg is already upload I just add it to output array but maintain it in a order (if the link added was 2nd in array the output result should also show it in 2nd)
So what function should be used to remove the matched urls from input array and a function to add it output array in the order no.
// edited
Yes unset will do the thing but I want to maintain the order:
For example after unsetting the array looks like this:
Array (
[0] => http://i41.tinypic.com/3342r93.jpg
// [1] was removed
[2] => http://i41.tinypic.com/12dsa32.jpg
)
but the output array would be
Array
(
[0] => Array
(
[id] => 43
[name] => 3342r93.jpg
[size] => 362750
[descr] =>
[password] =>
[delete_id] => 75CE
[upload_id] => 75F45CAE1
)
// this will become [1], so how can i add another output[1] and shift other
// items after it to [2], [3] and so on...
[1] => Array
(
[id] => 45
[name] => 12dsa32.jpg
[size] => 49000
[descr] =>
[password] =>
[delete_id] => 54C9
[upload_id] => A58614C01
)
)
Well, you can add it to the output array by doing something like:
$OutArray[2] = $element;
Where $element is another Array with the id, name, size (etc...) elements.
As for removing from the array:
unset($OutArray[2]);
You may want to read Array (PHP manual).
If you have an indexed array, you can remove a value by doing:
unset ($array[2]);
If you want to add an item to an array, use this shorthand of array_push (you don't need to specify an index!):
$array[] = "new object";
All documentation is on php.net/arrays
Why don't use an if statement and/or file_exists() to see if the file is there. If you already have an array with the values then it just won't be uploaded again.