So I've got a series of arrays that look like this:
object(Illuminate\Support\Collection)[214]
protected 'items' =>
array (size=1)
0 =>
array (size=2)
'data' => string 'test'
'user' => string 'testmail#testing.com'
object(Illuminate\Support\Collection)[215]
protected 'items' =>
array (size=1)
0 =>
array (size=2)
'data' => string 'Awesome test'
'user' => string 'tester#mail.com'
object(Illuminate\Support\Collection)[220]
protected 'items' =>
array (size=2)
0 =>
array (size=2)
'data' => string ' A string'
'user' => string 'different.tester#mail.com'
1 =>
array (size=2)
'data' => string 'Another string again'
'user' => string 'different.tester#mail.com'
I'm wanting to loop through each array and send the data values to the relevant user.
So different.tester#mail.com would receive 'A string' and 'Another string again' for example.
I'm totally stuck on this and would welcome any feedback!
Thanks
Related
object(SimpleXMLElement)[803]
public 'row' =>
array (size=13)
0 =>
object(SimpleXMLElement)[797]
public '#attributes' =>
array (size=4)
'codeonimage' => string '01' (length=2)
'name' => string 'Крышка' (length=12)
'oem' => string '13711251885' (length=11)
'ssd' => string '$HgsQRnNPF0d$' (length=174)
public 'attribute' =>
array (size=2)
0 =>
object(SimpleXMLElement)[813]
public '#attributes' =>
array (size=3)
'key' => string 'amount' (length=6)
'name' => string 'Количество' (length=20)
'value' => string '1' (length=1)
1 =>
object(SimpleXMLElement)[814]
public '#attributes' =>
array (size=3)
'key' => string 'end_of_production' (length=17)
'name' => string 'end_of_production' (length=17)
'value' => string 'Не производтся с: 19871116' (length=40)
...
I'm trying to take all the 'oem' values from each SimpleXML element like:
array_column($simpleXMLObject->row, 'oem');
... and of course I get an error:
array_column() expects parameter 1 to be array, object given
There is another option with a full search. But maybe there is some more pretty way to do this?
I've got a very large JSON file that I've converted into an array. The code you see below is the result of
var_dump($array['talents'])
(for those wondering, yes, this is me attempting to use Blizzard Entertainment's API)
Maybe I just missed that day at PHP school, but I just can't seem to remember or figure out how to get the values inside these deeper arrays. And perhaps more importantly, pay attention to the two 'spec' fields - ONE of them has a value of 'SELECTED: BOOLEAN TRUE', and the other does not. Basically, I need the NAME field from the array that has that SELECTED value.
To be honest, much as I love working in PHP, this multi-level thinking is a tad beyond me at the moment, I need some more experience. In the meantime, could anyone give me some tips, pointers, or just straight-up answers as to how I can get the value I need?
Thanks a bunch for your time!
array (size=2)
0 =>
array (size=6)
'talents' =>
array (size=6)
0 =>
array (size=3)
...
1 =>
array (size=3)
...
2 =>
array (size=3)
...
3 =>
array (size=3)
...
4 =>
array (size=3)
...
5 =>
array (size=3)
...
'glyphs' =>
array (size=2)
'major' =>
array (size=0)
...
'minor' =>
array (size=1)
...
'spec' =>
array (size=6)
'name' => string 'Frost' (length=5)
'role' => string 'DPS' (length=3)
'backgroundImage' => string 'bg-mage-frost' (length=13)
'icon' => string 'spell_frost_frostbolt02' (length=23)
'description' => string 'Freezes enemies in their tracks and shatters them with Frost magic.' (length=67)
'order' => int 2
'calcTalent' => string '120021.' (length=7)
'calcSpec' => string 'b' (length=1)
'calcGlyph' => string 'O' (length=1)
1 =>
array (size=7)
'selected' => boolean true
'talents' =>
array (size=6)
0 =>
array (size=3)
...
1 =>
array (size=3)
...
2 =>
array (size=3)
...
3 =>
array (size=3)
...
4 =>
array (size=3)
...
5 =>
array (size=3)
...
'glyphs' =>
array (size=2)
'major' =>
array (size=0)
...
'minor' =>
array (size=0)
...
'spec' =>
array (size=6)
'name' => string 'Fire' (length=4)
'role' => string 'DPS' (length=3)
'backgroundImage' => string 'bg-mage-fire' (length=12)
'icon' => string 'spell_fire_firebolt02' (length=21)
'description' => string 'Ignite enemies with balls of fire and combustive flames.' (length=56)
'order' => int 1
'calcTalent' => string '122012.' (length=7)
'calcSpec' => string 'Z' (length=1)
'calcGlyph' => string '' (length=0)
should be
print_r($array['talents'][0]);
print_r($array['glyphs']['major']);
I have an array like
array (size=1)
'images' =>
array (size=3)
0 =>
array (size=4)
'image_name' => string 'image name' (length=10)
'image__seo_name' => string 'image-name' (length=10)
'image_path' => string 'C:/wamp/www/folder/images/products/image.png' (length=45)
'image_original_name' => string 'altinorfozotel7.png' (length=19)
1 =>
array (size=4)
'image_name' => string 'image name 2' (length=12)
'image_seo_name' => string 'image-name-2' (length=12)
'image_path' => string 'C:/wamp/www/folder/images/products/image2.png' (length=46)
'image_original_name' => string 'altinorfozotel3.png' (length=19)
2 =>
array (size=4)
'image_name' => string 'image name 3' (length=12)
'image_seo_name' => string 'image-name-3' (length=12)
'image_path' => string 'C:/wamp/www/folder/images/products/image3.png' (length=46)
'image_original_name' => string 'altinorfozotel4.png' (length=19)
I unset array['images'][0] key and need to reorder array keys in array['images'] array
I tried to use array_values($array['images']) but 'images' array key changed to 0 index.
$array['images'] = array_values($array['images']);
should work
I have just implemented https://github.com/thujohn/twitter-l4 for Laravel 4, it basically pulls in an array
of tweets from a search of a hashtag.
It seems like its working, I think there are some things that are not working though.
I get a blank screen with no errors which means a positive sign.
Here is my code.
PHP:
$tweets = Twitter::getSearch(array('q' => 'secretsocial', 'count' => 100, 'format' => 'array'));
var_dump($tweets);
This code basically gives me an array of json:
array (size=2)
'statuses' =>
array (size=20)
0 =>
array (size=24)
'metadata' =>
array (size=2)
'result_type' => string 'recent' (length=6)
'iso_language_code' => string 'en' (length=2)
'created_at' => string 'Fri May 16 14:28:14 +0000 2014' (length=30)
'id' => int 467310562603331586
'id_str' => string '467310562603331586' (length=18)
'text' => string 'On that #merch #grind. #spotify #swag just got shipped in. #secretsocial #free #leeds #leedsuni… http://t.co/67phqjeg5W' (length=121)
'source' => string 'Instagram' (length=59)
'truncated' => boolean false
'in_reply_to_status_id' => null
'in_reply_to_status_id_str' => null
'in_reply_to_user_id' => null
'in_reply_to_user_id_str' => null
'in_reply_to_screen_name' => null
'user' =>
array (size=40)
'id' => int 167993141
'id_str' => string '167993141' (length=9)
'name' => string 'Maral Erol' (length=10)
'screen_name' => string 'liaaca' (length=6)
'location' => string 'Leeds / San Diego' (length=17)
'description' => string 'Music/Culture/Entertainment Enthusiast.' (length=39)
'url' => string 'http://t.co/FL3uuA6QcN' (length=22)
'entities' =>
array (size=2)
'url' =>
array (size=1)
'urls' =>
array (size=1)
0 =>
array (size=4)
'url' => string 'http://t.co/FL3uuA6QcN' (length=22)
'expanded_url' => string 'http://linkd.in/R70tjB' (length=22)
'display_url' => string 'linkd.in/R70tjB' (length=15)
'indices' =>
array (size=2)
0 => int 0
1 => int 22
'description' =>
array (size=1)
'urls' =>
array (size=0)
empty
So from that I wrote this:
if(isset($tweets->statuses) && is_array($tweets->statuses)) {
if(count($tweets->statuses)) {
foreach($tweets->statuses as $tweet) {
echo $tweet->text;
}
}
else {
echo 'The result is empty';
}
}
I get no errors on the page. Can anyone point me in the right direction please?
Cheers
Since each $tweet is an array so you should use $tweet['text'] instead of $tweet->text
foreach($tweets->statuses as $tweet) {
echo $tweet['text'];
}
Also $tweets->statuses should be $tweets['statuses'].
I have the following Simple XML structure var_dump'ed:
var_dump($data) results in:
object(SimpleXMLElement)[269]
public 'columns' =>
object(SimpleXMLElement)[283]
public 'column' =>
array (size=11)
0 =>
object(SimpleXMLElement)[274]
public '#attributes' =>
array (size=2)
'name' => string 'test' (length=10)
'display' => string 'test ID' (length=11)
1 =>
object(SimpleXMLElement)[273]
public '#attributes' =>
array (size=2)
'name' => string 'blah' (length=8)
'display' => string 'blah' (length=8)
....
....
....
public 'row' =>
array (size=6)
0 =>
object(SimpleXMLElement)[270]
public '#attributes' =>
array (size=11)
'test' => string '3445543' (length=8)
'blah' => string 'Some Text' (length=13)
1 =>
object(SimpleXMLElement)[279]
public '#attributes' =>
array (size=11)
'test' => string '3445543' (length=8)
'blah' => string 'Some Text' (length=13)
2 =>
object(SimpleXMLElement)[278]
....
....
....
I shortened the output as you can see just to save room. But the row array contains 6 elements as you can see.
Now if I do this:
echo count($data->row); I get 6 as expected.
If I do this:
var_dump($data->row); I get this...
object(SimpleXMLElement)[270]
public '#attributes' =>
array (size=11)
'test' => string '3445543' (length=8)
'blah' => string 'Some Text' (length=13)
It prints out one element. No array.
Why would the count of the array return the right value but fetching the array only gets the first element of the array? How do I get all of the elements?