Array
(
[response] => Array
(
[success] => 1
[result] => Array
(
[success] => Array
(
[0] => Array
(
[id] => 1958856
[device_id] => 7565
[message] => ....
[status] => pending
[send_at] => 1416564932
[queued_at] => 0
[sent_at] => 0
[delivered_at] => 0
[expires_at] => 1416568532
[canceled_at] => 0
[failed_at] => 0
[received_at] => 0
[error] =>
[created_at] => 1416564932
[contact] => Array
(
[id] => 312505
[name] => 123
[number] => 123
)
)
)
[fails] => Array
(
)
)
)
[status] => 200
i need to get [id] => 1958856.
$array['response']['result']['success'][0]['id'];
this should get to it
Additional details from iWontStop:
How it works
This is called a multi-dimensional array. They're found in many languages (most useful ones I'd say).
To access an item within the Array, for php it uses []. You can then place a string, number or variable containing one of the two within the [] like so:
$variable['key'];
If an item within an Array is also an Array you simply repeat the process of the [] like so:
$variable['key']['keytwo'];
Related
so the output is already shared formate. the final array should me array one value and array two value without any 0 and 1 index only the second array value need to add the same response
**// array one
Array
(
[success] => 1
[message] => success
[status_code] => 0
[data] => Array
(
[email] => naeemmalik036#gmail.com
)
[http_response] => 200
)
// array two
Array
(
[success] => 1
[message] => success
[status_code] => 0
[data] => Array
(
[name] => ram
)
[http_response] => 200
)
// output needed like this //
Array
(
[success] => 1
[message] => success
[status_code] => 0
[data] => Array
(
[email] => naeemmalik036#gmail.com
[name] => ram
)
[http_response] => 200
)**
You Can Simply Merge The Array And Re-Assign To Any Array
$array2['data'] = array_merge($array['data'],$array2['data']);
print_r($array2);
I have text file of array values
for example
[26-11-2018 04:07:26]: Array
(
[0] => api.flights_published_search
[1] => Array
(
[0] => Array
(
[ticket_type] => single
[departure_airport_id] => THR
[arrival_airport_id] => MHD
[departure_date] => 21/12/2018
[direct_flight_only] => 0
[adults] => 1
[children] => 1
[child_ages] => Array
(
[1] => 11
)
[infants] => 1
[cabin_class] => Y
)
)
)
[26-11-2018 04:07:27]: Array
(
[status] => 1
[pscId] => 0
[localInventory] => Array
(
[cal] => 0
[resp] => Array
(
)
)
[error] => Array
(
[status] =>
[error] => Error Code: 3037, Error: No availability on chosen flights.
)
)
I want to convert into as it is in array through php coding . so can anyone suggegst best way to convert this text to php array
I am trying to display the data from Bigcommerce through php when I run the Bigcommerce::getCategories() i getting a array of data like this:
[0] => Bigcommerce\Api\Resources\Category Object
(
[ignoreOnCreate:protected] => Array
(
[0] => id
[1] => parent_category_list
)
[ignoreOnUpdate:protected] => Array
(
[0] => id
[1] => parent_category_list
)
[fields:protected] => stdClass Object
(
[id] => 88
[parent_id] => 0
[name] => Dell
[description] =>
[sort_order] => 0
[page_title] =>
[meta_keywords] =>
[meta_description] =>
[layout_file] =>
[parent_category_list] => Array
(
[0] => 88
)
[image_file] =>
[is_visible] => 1
[search_keywords] =>
[url] => /dell/
)
[id:protected] => 88
[ignoreIfZero:protected] => Array
(
)
[fieldMap:protected] => Array
(
)
)
but when I try to pass this to JQuery so that I can display it using this statement: <?php echo json_encode($categories); ?> I am getting an array of empty objects, what is the right way to get the array of objects in Bigcommerce API? Thanks.
From the first line of your code:
[0] => Bigcommerce\Api\Resources\Category Object
You have an object, not an array. Try casting it to an array first:
$array = (array) $yourObject;
I'm having trouble modeling my database. Currently it looks like this (I'm hiding the irrelevant fields): http://i.imgur.com/SF9FzaD.png
It is working fine, for example, when I want it to return a list of all the servers:
$this->Server->find('all');
It returns an array with the right information:
Array
(
[0] => Array
(
[Server] => Array (...)
[User] => Array (...)
[Highlight] => Array
(
[0] => Array
(
[id] => 39
[id_server] => 8
[id_highlight] => 1
)
[1] => Array
(
[id] => 40
[id_server] => 8
[id_highlight] => 5
)
)
[SubServer] => Array(...)
)
[1] => Array
(
[Server] => Array (...)
[User] => Array (...)
[Highlight] => Array
(
[0] => Array
(
[id] => 41
[id_server] => 10
[id_highlight] => 4
)
[1] => Array
(
[id] => 42
[id_server] => 10
[id_highlight] => 5
)
)
[SubServer] => Array(...)
)
)
In short, each game "server" has some kind of higlights pointed by the user. Like "Anti-cheat system", "Active staff", "Custom events", etc. Each of these highlights have an id and a name.
Is there a way to grab the name from the table highlight_names corresponding to each of the highlights.id_hightlight (and the rest of the data, like the array above) using Model::find()?
I wonder if it's possible to add a key and value to an array, based on certain conditions.
This piece of script makes an api-call to retrieve sportresults from multiple teams based on a teamID number.
$length = $numberofTeams
for ($i = 0; $i < $length; $i++) {
$teamID = $objTeamID[$i]['Teamid'];
$teamResults = 'http://api.com/teamresults/' . $Teamid;
$dataResults = file_get_contents($teamResults);
$objResults[] = json_decode($dataResults, true);
}
The result is an array with this structure:
Array (
[0] => Array (
[errorcode] => 9995
[message] => No results
)
[1] => Array (
[errorcode] => 1000
[message] => Ok, Schedule follows
[List] => Array (
[0] => Array (
[MatchID] => 7683403
[Number] => 630
[Result] => 2 - 1
[Datum] => 2013-08-27
[Tijd] => 2000
[CompType] => B )
[1] => Array (
[MatchID] => 7683403
[Number] => 630
[Result] => 4 - 0 [Datum] => 2013-08-27
[Tijd] => 2000
[CompType] => B )
)
)
[2] => Array (
[errorcode] => 9995
[message] => No results )
)
Before saving it in an MySql database, for later use I need to add the teamID-variable to every result so it would become:
Array (
[0] => Array (
[errorcode] => 9995
[message] => No results
)
[1] => Array (
[errorcode] => 1000
[message] => Ok, Schedule follows
[List] => Array (
[0] => Array (
[teamID] => 'value from $teamID'
[MatchID] => 7683403
[Number] => 630
[Result] => 2 - 1
[Datum] => 2013-08-27
[Tijd] => 2000
[CompType] => B )
[1] => Array (
[teamID] => 'value from $teamID' [MatchID] => 7683403
[Number] => 630
[Result] => 4 - 0
[Datum] => 2013-08-27
[Tijd] => 2000
[CompType] => B )
)
)
[2] => Array (
[errorcode] => 9995
[message] => No results )
)
The length of the array varies and also the number of results vary. I have no influence on the result of the api-call itself, because it's been set up by big sport association.
I'm absolutely no programmer, so I'm out of my depth her, but this is a voluntary job for an amateur sportsclub so hiring a programmer is no option.
Rgds, Bonzyx
if(isset($objResults[1]['List'])){
foreach($objResults[1]['List'] as &$listItem){
$listItem['teamID'] = $teamID;
}
unset($listItem); //good practice to unset this reference to last array element
}
You could do the same with php's array_walk() function, but since you said you're not a programmer I think the foreach method is more clear to you.