Hello people here is the code that i was using initially....
array_push($Parameter_IdArray, $Parameter_Id1, $Parameter_Id2, $Parameter_Id3, $OptParameter_Id);
array_push($Eqt_ParamArray, $eqt_param1, $eqt_param2, $eqt_param3, $Opt_eqt_param1);
i had no issues to push array values .... but now $eqt_param1, $eqt_param2, $eqt_param3 and $Opt_eqt_param1 are in one more array it is something like this
Array ( [Profile_Id] => 4 [eqt_param] => Array ( [0] => 4.00 [1] => 4.00 [2] => 4.00 ) [Parameter_Id1] => 8 [min_param] => Array ( [0] => 1.00 [1] => 1.00 [2] => 1.00 ) [max_param] => Array ( [0] => 5.00 [1] => 5.00 [2] => 5.00 ) [Wtg_param] => Array ( [0] => 25.00 [1] => 25.00 [2] => 50.00 ) [Parameter_Id2] => 5 [Parameter_Id3] => 1 [Opt_eqt_param] => Array ( [0] => 0.00 ) [OptParameter_Id] => 14 [Opt_wtg] => Array ( [0] => 1.05 ) [operator] => Array ( [0] => M ) [eqt_pay] => 1,574,235 [rec_sal] => 1,485,000 [#] => -6.01 % [Emp_Id] => 490699 [Emp_Process] => Confirm New Pay )
now i need tp push array values $eqt_param1, $eqt_param2, $eqt_param3 and $Opt_eqt_param1 to $Eqt_ParamArray how to do that?
If I understand correctly, you've now got an associative array in PHP. On that assumption, I went ahead and reformatted the nightmare for you:
$myarray = array(
"Profile_Id" => 4,
"eqt_param" => array(4.00, 4.00, 4.00),
"Parameter_Id1" => 8,
"min_param" => array (1.00, 1.00, 1.00 ),
"max_param" => array (5.00, 5.00, 5.00 ),
"Wtg_param" => array (25.00, 25.00, 50.00 ),
"Parameter_Id2" => 5,
"Parameter_Id3" => 1,
"Opt_eqt_param" => array (0.00),
"OptParameter_Id" => 14,
"Opt_wtg" => array (1.05),
"operator" => array ("M"),
"eqt_pay" => array(1,574,235),
"rec_sal" => array(1,485,000),
"#" => "-6.01 %",
"Emp_Id" => 490699,
"Emp_Process" => "Confirm New Pay"
);
What this good formatting now makes clear is that you can use array_push directly on the "eqt_param" index:
array_push($myArray["eqt_param"], $eqt_param1, $eqt_param2, $eqt_param3, $Opt_eqt_param1);
You may also mean that you want to replace it, which is easy too:
$myArray['eqt_param'] = array($eqt_param1, $eqt_param2, $eqt_param3, $Opt_eqt_param1);
The same principles apply in Javascript, which you have had tagged so maybe you mean that.
Related
Ok, this question was probably asked many times here. Tried searching for a way that works but I dont find the correct term to search it.
I have following 2 array
Array 1
Array
(
[1] => Array
(
[data] => DFF022
)
[2] => Array
(
[data] => DFF026
)
)
Array 2
Array
(
[0] => Array
(
[number] => INC0000002
[ia] =>
[description] => Printer not working
[state] => Monitoring - Waiting for Client
[updated] => 12/30/2020 19.09.01
[opened] => 12/24/2020 20.35.36
)
[1] => Array
(
[number] => INC0000003
[ia] =>
[description] => Monitor broke down
[state] => Pending - Awaiting Change Approval/Implementation
[updated] => 12/29/2020 23.57.06
[opened] => 12/29/2020 08.21.38
)
)
Now the number of item inside the array is always will be same. If array 1 got 10 items, then array 2 will have 10 items as well.
I'm looking a way to merge the array to something like this
Array
(
[0] => Array
(
[number] => INC1879727
[ia] =>
[description] => Unable to replay CME NS message
[state] => Monitoring - Waiting for Client
[updated] => 12/30/2020 19.09.01
[opened] => 12/24/2020 20.35.36
[data] => DFF022
)
[1] => Array
(
[number] => INC1884171
[ia] =>
[description] => mw_uat - UAT00MSV_LNP6_01_pga_aggregate_limit
[state] => Pending - Awaiting Change Approval/Implementation
[updated] => 12/29/2020 23.57.06
[opened] => 12/29/2020 08.21.38
[data] => DFF026
)
)
Any idea on how to accomplish this?
Using array merge or combine just combines the array and I have double the items I wanted.
You can run a foreach() to inject the data. To directly modify array elements of $arr2 within the loop we precede $value with &, so the value is assigned by reference:
<?php
$arr1 = [
['data' => 'DFF022',],
['data' => 'DFF026',],
];
$arr2 = [
[
'number' => 'INC0000002',
'ia' => '',
'description' => 'Printer not working',
'state' => 'Monitoring - Waiting for Client',
'updated' => '12/30/2020 19.09.01',
'opened' => '12/24/2020 20.35.36',
],
[
'number' => 'INC0000003',
'ia' => '',
'description' => 'Monitor broke down',
'state' => 'Pending - Awaiting Change Approval/Implementation',
'updated' => '12/29/2020 23.57.06',
'opened' => '12/29/2020 08.21.38',
],
];
foreach($arr2 as $key => &$value) {
$value['data'] = $arr1[$key]['data'];
}
Output (print_r($arr2)):
Array
(
[0] => Array
(
[number] => INC0000002
[ia] =>
[description] => Printer not working
[state] => Monitoring - Waiting for Client
[updated] => 12/30/2020 19.09.01
[opened] => 12/24/2020 20.35.36
[data] => DFF022
)
[1] => Array
(
[number] => INC0000003
[ia] =>
[description] => Monitor broke down
[state] => Pending - Awaiting Change Approval/Implementation
[updated] => 12/29/2020 23.57.06
[opened] => 12/29/2020 08.21.38
[data] => DFF026
)
)
working demo
First off, I'm new to PHP and coding in general, so this might be quite an obvious answer.
I'm currently working with the Strava API, and I'm trying to extract data from an Array/Object which is the result of the following API call:
$recentactivities = $api->get('athlete/activities', array('per_page' => 100));
which returns:
Array (
[1] => stdClass Object (
[id] => XXXX
[resource_state] => 2
[external_id] => XXXX
[upload_id] => XXXX
[athlete] => stdClass Object (
[id] => XXXX
[resource_state] => 1
)
[name] => Let\'s see if I can remember how to do this cycling malarkey...
[distance] => 11858.3
[moving_time] => 1812
[elapsed_time] => 2220
[total_elevation_gain] => 44
[type] => Ride
[start_date] => 2014-07-12T13:48:17Z
[start_date_local] => 2014-07-12T14:48:17Z
[timezone] => (
GMT+00:00
) Europe/London
[start_latlng] => Array (
[0] => XXXX
[1] => XXXX
)
[end_latlng] => Array (
[0] => XXXX
[1] => -XXXX
)
[location_city] => XXXX
[location_state] => England
[location_country] => United Kingdom
[start_latitude] => XXXX
[start_longitude] => XXXXX
[achievement_count] => 4
[kudos_count] => 1
[comment_count] => 0
[athlete_count] => 1
[photo_count] => 0
[map] => stdClass Object (
[id] => a164894160
[summary_polyline] => XXXX
[resource_state] => 2
)
[trainer] =>
[commute] =>
[manual] =>
[private] =>
[flagged] =>
[gear_id] => b739244
[average_speed] => 6.544
[max_speed] => 10.8
[average_cadence] => 55.2
[average_temp] => 29
[average_watts] => 99.3
[kilojoules] => 179.9
[device_watts] =>
[average_heartrate] => 191.2
[max_heartrate] => 200
[truncated] =>
[has_kudoed] =>
)
This repeats for the most recent activities.
I'm attempting to extract average_heartrate, which I can do for a single object using the following:
$recentactivities[1]->average_heartrate;
but I'd like to extract all instances of average_heartrate from the Array. I've tried to use a foreach statement, but to be honest, I have no idea where to start.
Any help would be much appreciated.
It's actually pretty simple you can indeed use a foreach loop:
foreach($myArray as $obj){
//$obj is an object so:
if(isset($obj->average_heartrate)){
echo $obj->average_heartrate;
}
}
With this code you iterate through your array with objects and save the wanted array within an array so you can work further with it.
$heartrateArray = array(); // create a new array
//iterate through it with an foreach
foreach($recentactivities as $activity){
// save the average_heartrate as a value under a new key in the array
$heartrateArray[] = $activity->average_heartrate;
}
I am fairly new to PHP and I am writing a PHP function that grabs an object from SOAP.
I found a code to convert it to an array but I can't manage to echo any data.
The array from print_r
Array
(
[Status] => Array
(
[Code] => 0
[Message] => OK
)
[Order] => Array
(
[OrderNumber] => 9334543
[ExternalOrderNumber] =>
[OrderTime] => 2014-07-15T15:20:31+02:00
[PaymentMethod] => invoice
[PaymentStatus] => Paid
[ShipmentMethod] => Mypack
[DeliveryStatus] => Delivered
[Language] => sv
[Customer] => Array
(
[CustomerId] => 13556
[CustomerNumber] =>
[Username] => admin
[Approved] => 1
[OrgNumber] => 9309138445
[Company] =>
[VatNumber] =>
[FirstName] => Jane
[LastName] => Doe
[Address] => Gatan
[Address2] =>
[Zip] => 1230
[City] => Staden
[Country] => Sweden
[CountryCode] => SE
[PhoneDay] => 84848474
[PhoneNight] =>
[PhoneMobile] =>
[Email] => mail#msn.com
[NewsLetter] =>
[OrgType] => person
[OtherDelivAddress] =>
[DelivName] =>
[DelivAddress] =>
[DelivAddress2] =>
[DelivZip] =>
[DelivCity] =>
[DelivCountry] =>
[DelivCountryCode] =>
)
[Comment] =>
[Notes] => 9063025471 UK/MA
[CurrencyCode] => SEK
[ExchangeRate] => 1
[LanguagePath] => se
[FreightWithoutVat] => 0
[FreightWithVat] => 0
[FreightVatPercentage] => 25
[PayoptionFeeWithoutVat] => 0
[PayoptionFeeWithVat] => 0
[PayoptionFeeVatPercentage] => 25
[CodWithoutVat] => 0
[CodWithVat] => 0
[CodVatPercentage] => 0
[DiscountWithoutVat] => 0
[DiscountWithVat] => 0
[DiscountVat] => 0
[TotalWithoutVat] => 4388
[TotalWithVat] => 5485
[TotalVat] => 1097
[PayWithoutVat] =>
[AffiliateCode] =>
[AffiliateName] =>
[OrderField] => Array
(
[0] => Array
(
[Name] => external_ref
[Value] => 43445
)
[1] => Array
(
[Name] => webshopid
[Value] => 423
)
[2] => Array
(
[Name] => webshopname
[Value] => Manuell
)
)
)
)
Non working code
echo $array[1][0]
I have tried different combos of indexes. I know how to return the values from the soap object but if I could do it this way it would be easier. It should work shouldn't it?
$array[1] is the second index of the array. the key of this array us "Status", this array contains a code and message
i assume you want to echo the message, you can do that with the following
echo $array[1]["Status"]["Message"];
You should use $array['Status']['Code'] , $array['Status']['Message'], $array['Order']['OrderNumber'], $array['Order']['Customer']['CustomerId'] and so on to display your data. It's an associative array so you need to use string keys and not numbers
try
$array['Order']['Customer']['LastName']
is my best guess without losing my sanity in that one line.
But for us to be sure please post the print_r($array) output
There are some way I always do this:
print_r($array);
And the other way is
$array[0]['Order']['LastName']
Try to access the arrays elements with the string keys, not the integer ones you are using:
echo $array['Order']['Customer']['Address'];
Another way you could see what is going on is by iterating through the array, and print out the keys and values:
foreach ($array as $key => $value)
echo "Key=$key value=$value<br>";
Im trying to get latitude and longitude from an image. The exif gps array:
[GPS] => Array
(
[GPSVersion] =>
[GPSLatitudeRef] => N
[GPSLatitude] => Array
(
[0] => 57/1
[1] => 42/1
[2] => 45594/1000
)
[GPSLongitudeRef] => E
[GPSLongitude] => Array
(
[0] => 11/1
[1] => 54/1
[2] => 56615/1000
)
[GPSAltitudeRef] =>
[GPSAltitude] => 228/10
[GPSTimeStamp] => Array
(
[0] => 10/1
[1] => 46/1
[2] => 12000/1000
)
[GPSStatus] => A
[GPSMeasureMode] => 3
[GPSSpeedRef] => K
[GPSSpeed] => 4/10
[GPSTrackRef] => T
[GPSTrack] => 1719/100
[GPSImgDirectionRef] => M
[GPSImgDirection] => 32900/100
[GPSMapDatum] => WGS-84
[GPSDateStamp] => 2011:04:23
[GPSDifferential] => 0
)
I thought latitude would be 45594/1000 and longitude 56615/1000, but those values seems to be way of. Am i doing it wrong, or is the data incorrect? Thanks
I'd interpret:
[GPSLatitudeRef] => N
[GPSLatitude] => Array
(
[0] => 57/1
[1] => 42/1
[2] => 45594/1000
)
As 57 degrees, 42 minutes, 45 seconds, and 594 milliseconds North... Ergo: somewhere up in Canada or Siberia.
The next question is "What's the datum?", which is given in the [GPSMapDatum] => WGS-84 element.
Cheers. Keith.
PS: Google(WGS-84) says: http://en.wikipedia.org/wiki/World_Geodetic_System
PPS: Looking at http://www.worldpress.org/images/maps/europe_600w.jpg, I'd put that point in the North Sea close to the coast of Norway... Am I warm?
i was trying to access this php array with no luck, i want to access the [icon] => icon.png
Array ( [total] => 2
[total_grouped] => 2
[notifys] => Array ( [0] => Array ( [notifytype_id] => 12
[grouped] => 930
[icon] => icon.png
[n_url] => wall_action.php?id=930
[desc] => 690706096
[text] => Array ( [0] => Sarah O'conner ) [total] => 1 )))
$arr['notifys'][0]['icon']
ETA: I'm not sure what your comment means, the following code:
$arr = array('total'=>2, 'total_grouped' => 2, 'notifys' => array(array(
'notifytype_id' => 12, 'icon' => 'icon.png')));
echo '<pre>';
print_r($arr);
echo '</pre>';
var_dump($arr['notifys'][0]['icon']);
outputs:
Array
(
[total] => 2
[total_grouped] => 2
[notifys] => Array
(
[0] => Array
(
[notifytype_id] => 12
[icon] => icon.png
)
)
)
string(8) "icon.png"
Generally, code never outputs nothing. You should be developing with all errors and notifications on.
$arr['notifys'][0]['icon']
rg = Array ( [total] => 2 [total_grouped] => 2 [notifys] => Array ( [0] => Array ( [notifytype_id] => 12 [grouped] => 930 [icon] => icon.png [n_url] => wall_action.php?id=930 [desc] => 690706096 [text] => Array ( [0] => Sarah O'conner ) [total] => 1 )));
icon = rg["notifsys"][0]["icon"];
Everybody is posting right answer. Its just you have giving a wrong deceleration of array.
Try var_dump/print_r of array and then you can easily understand nodes.
$arr = array(total => 2,
total_grouped => 2,
notifys => array( 0 => array(notifytype_id => 12,
grouped => 930,
icon => 'icon.png',
n_url => 'wall_action.php?id=930',
desc => 690706096,
text =>array(0 => 'Sarah Oconner' ),
total => 1,
),
),
);
echo $arr['notifys']['0']['icon'];