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);
Related
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;
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'];
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.
I tried to get an answer for this in other posts with no luck, hope someone can help me here, i have a multidimensional array:
Array (
[0] => stdClass Object (
[affectsVersions] => Array ( )
[assignee] => hmontes
[attachmentNames] => Array ( )
[components] => Array ( )
[created] => 2012-08-15T05:31:26.000Z
[customFieldValues] => Array (
[0] => stdClass Object (
[customfieldId] => customfield_10201
[key] => [values] => Array (
[0] => 123456
)
)
[1] => stdClass Object (
[customfieldId] => customfield_10004
[key] => [values] => Array (
[0] => 30
)
)
)
[description] => [duedate] => [environment] => [fixVersions] => Array ( )
[id] => 10228
[key] => NTP-29
[priority] => 3
[project] => NTP
[reporter] => hmontes
[resolution] => [status] => 1
[summary] => case 123456
[type] => 3
[updated] => 2012-08-15T05:31:26.000Z
[votes] => 0
)
)
this is what i get when i do a print_r with the array variable, i need to search and get the value from [key] that would be in this case NTP-29 and keep it in a variable as string.
You can get the value of an array by the key using $array['keyName'];
But, for you it looks like you just need to go deeper $array[0]['key'];
Both arrays values and properties of objects can be accessed using associative array syntax. To get the value of the key property in your object within the array you'd do the following, assuming $array is a variable containing a reference to your array:
$key = $array[0]['key']; // accesses NTP-29 in this case.
Here's another way to access the same property, using object property-access syntax:
$key = $array[0]->key; // also accesses NTP-29.