I have the current array in PHP which is being extracted from a MySQL database (PDO fetch all);
[0] => Array
(
[id] => 78
[indent] => 2.2
[partnumber] => OPPN-39-596
[description] => BACK WASH NOZZLE - 32 DIA
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 1
[notes] =>
[partcost] =>
[totalcost] =>
)
[1] => Array
(
[id] => 23
[indent] => 2.3
[partnumber] => OPPN-21-508
[description] => FRONT 12MM JET ASSY
[size] =>
[rev] => A
[code] => ASY
[quantity] => 3
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[2] => Array
(
[id] => 17
[indent] => 2.3.1
[partnumber] => OPPN-21-356
[description] => INTERNAL CIRCLIP Ø42 BORE S/S
[size] =>
[rev] =>
[code] => HRD
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[3] => Array
(
[id] => 26
[indent] => 2.3.2
[partnumber] => OPPN-21-509
[description] => FRONT JET 12MM NOZZLE
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[4] => Array
(
[id] => 28
[indent] => 2.3.3
[partnumber] => OPPN-21-510
[description] => FLOW STRAIGHTENER 12MM INSERT 1
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[5] => Array
(
[id] => 30
[indent] => 2.3.4
[partnumber] => OPPN-21-511
[description] => FLOW STRAIGHTENER 12MM INSERT 2
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[6] => Array
(
[id] => 34
[indent] => 2.3.5
[partnumber] => OPPN-21-524
[description] => O RING 3.53 X 32.92 ID NITRILE
[size] =>
[rev] => A
[code] => HRD
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[7] => Array
(
[id] => 76
[indent] => 2.4
[partnumber] => OPPN-39-592
[description] => FRONT 14MM JET ASSY
[size] =>
[rev] => A
[code] => ASY
[quantity] => 10
[total] => 10
[notes] =>
[partcost] =>
[totalcost] =>
)
[8] => Array
(
[id] => 67
[indent] => 2.4.1
[partnumber] => OPPN-39-581
[description] => FRONT JET 14MM NOZZLE
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 10
[notes] =>
[partcost] =>
[totalcost] =>
)
I need to come up with some code to convert the array to this;
[0] => Array
(
[id] => 78
[indent] => 2.2
[partnumber] => OPPN-39-596
[description] => BACK WASH NOZZLE - 32 DIA
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 1
[notes] =>
[partcost] =>
[totalcost] =>
)
[1] => Array
(
[id] => 23
[indent] => 2.3
[partnumber] => OPPN-21-508
[description] => FRONT 12MM JET ASSY
[size] =>
[rev] => A
[code] => ASY
[quantity] => 3
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
[0] => Array
(
[id] => 17
[indent] => 2.3.1
[partnumber] => OPPN-21-356
[description] => INTERNAL CIRCLIP Ø42 BORE S/S
[size] =>
[rev] =>
[code] => HRD
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[1] => Array
(
[id] => 26
[indent] => 2.3.2
[partnumber] => OPPN-21-509
[description] => FRONT JET 12MM NOZZLE
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[2] => Array
(
[id] => 28
[indent] => 2.3.3
[partnumber] => OPPN-21-510
[description] => FLOW STRAIGHTENER 12MM INSERT 1
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[3] => Array
(
[id] => 30
[indent] => 2.3.4
[partnumber] => OPPN-21-511
[description] => FLOW STRAIGHTENER 12MM INSERT 2
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
[4] => Array
(
[id] => 34
[indent] => 2.3.5
[partnumber] => OPPN-21-524
[description] => O RING 3.53 X 32.92 ID NITRILE
[size] =>
[rev] => A
[code] => HRD
[quantity] => 1
[total] => 3
[notes] =>
[partcost] =>
[totalcost] =>
)
)
[2] => Array
(
[id] => 76
[indent] => 2.4
[partnumber] => OPPN-39-592
[description] => FRONT 14MM JET ASSY
[size] =>
[rev] => A
[code] => ASY
[quantity] => 10
[total] => 10
[notes] =>
[partcost] =>
[totalcost] =>
[0] => Array
(
[id] => 67
[indent] => 2.4.1
[partnumber] => OPPN-39-581
[description] => FRONT JET 14MM NOZZLE
[size] =>
[rev] => A
[code] => MCH
[quantity] => 1
[total] => 10
[notes] =>
[partcost] =>
[totalcost] =>
)
)
[3] => Array
(
[id] => 76
[indent] => 2.5
[partnumber] => OPPN-39-592
[description] => FRONT 14MM JET ASSY
[size] =>
[rev] => A
[code] => ASY
[quantity] => 10
[total] => 10
[notes] =>
[partcost] =>
[totalcost] =>
)
The array element with an indent of 2.3.1 becomes a child element of the element which has an indent of 2.3 and so on... I need to come up with some code that automatically formats this array to way I need it. I have fighting with multi dimensional for loops all day now but had no luck. Any guidance and assistance would be appreciated.
I have created snippet strongly coupled for your requirement, have a look.
$result = [];
foreach ($inputArr as $key => $value) {
$indentArr = explode('.', $value['indent']);
if (count($indentArr) == 2) {
$result[$value['indent']] = $value;
} else {
unset($indentArr[2]);
$parentIndent = implode('.',$indentArr);
$result[$parentIndent][] = $value;
}
}
Demo.
I have put together this code which will work as long as your top level is always "x.x", for example "1.0" and not just "1" , I then tested it using your given data as $values variable. Hope this helps.
//An array for all the grouped elements
$grouped = array();
foreach( $values as $key=>$properties ){
//Get the first two figures (and D.P) of the indent
$indent = substr( $properties['indent'], 0, 3 );
//Does this indent number already exist in the
if( !in_array( $indent, array_keys( $grouped ) ) ){
//Create a new parent element
$grouped[ $indent ] = $properties;
} else {
//Create a new child element
$grouped[ $indent ][] = $properties;
}
}
//Replace indent keys with numeric keys
$grouped = array_values( $grouped );
//Display
echo '<pre>' . print_r( $grouped, 1 ) . '</pre>';
Related
I am trying to convert an multi-dimentional array of product data where the PayPal email is set as one of the array values(can be same for some). I need help on merging those as arrays where the paypal_email key is same. Here is the print_r of the array that I have.
Array
(
[0] => Array
(
[name] => Test Product
[product_id] => 307
[variation_id] => 0
[subtotal] => 30
[total] => 30
[quantity] => 2
[subtotal_tax] => 2.66
[total_tax] => 2.66
[paypal_email] => thisismytestpaypal#sandbox.com
[vendor_id] => 2
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[1] => Array
(
[name] => Album
[product_id] => 354
[variation_id] => 0
[subtotal] => 15
[total] => 15
[quantity] => 1
[subtotal_tax] => 1.33
[total_tax] => 1.33
[paypal_email] => thisismytestpaypal#sandbox.com
[vendor_id] => 11
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[2] => Array
(
[name] => Beanie with Logo
[product_id] => 357
[variation_id] => 0
[subtotal] => 18
[total] => 18
[quantity] => 1
[subtotal_tax] => 1.60
[total_tax] => 1.60
[paypal_email] => ab2#sandbox.com
[vendor_id] => 10
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[3] => Array
(
[name] => Long Sleeve Tee
[product_id] => 352
[variation_id] => 0
[subtotal] => 75
[total] => 75
[quantity] => 3
[subtotal_tax] => 6.66
[total_tax] => 6.66
[paypal_email] => ab2#sandbox.com
[vendor_id] => 2
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[4] => Array
(
[name] => Polo
[product_id] => 353
[variation_id] => 0
[subtotal] => 80
[total] => 80
[quantity] => 4
[subtotal_tax] => 7.10
[total_tax] => 7.10
[paypal_email] => tv3#sandbox.com
[vendor_id] => 8
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[5] => Array
(
[name] => Product From Test Vendor 3
[product_id] => 145
[variation_id] => 0
[subtotal] => 60
[total] => 60
[quantity] => 3
[subtotal_tax] => 5.33
[total_tax] => 5.33
[paypal_email] => tv3#sandbox.com
[vendor_id] => 10
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[6] => Array
(
[name] => Product From Vendor 1
[product_id] => 143
[variation_id] => 0
[subtotal] => 20
[total] => 20
[quantity] => 2
[subtotal_tax] => 1.78
[total_tax] => 1.78
[paypal_email] => tv1#sandbox.com
[vendor_id] => 8
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
)
I need the array to merged as a multi-dimentional array with the paypal email as key and other data as values.. For example,
Array
( [thisismytestpaypal#sandbox.com] => Array
(
[0] => Array
(
[name] => Test Product
[product_id] => 307
[variation_id] => 0
[subtotal] => 30
[total] => 30
[quantity] => 2
[subtotal_tax] => 2.66
[total_tax] => 2.66
[paypal_email] => thisismytestpaypal#sandbox.com
[vendor_id] => 2
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[1] => Array
(
[name] => Album
[product_id] => 354
[variation_id] => 0
[subtotal] => 15
[total] => 15
[quantity] => 1
[subtotal_tax] => 1.33
[total_tax] => 1.33
[paypal_email] => thisismytestpaypal#sandbox.com
[vendor_id] => 11
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
)
[ab2#sandbox.com] => Array
(
[0] => Array
(
[name] => Beanie with Logo
[product_id] => 357
[variation_id] => 0
[subtotal] => 18
[total] => 18
[quantity] => 1
[subtotal_tax] => 1.60
[total_tax] => 1.60
[paypal_email] => ab2#sandbox.com
[vendor_id] => 10
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[1] => Array
(
[name] => Long Sleeve Tee
[product_id] => 352
[variation_id] => 0
[subtotal] => 75
[total] => 75
[quantity] => 3
[subtotal_tax] => 6.66
[total_tax] => 6.66
[paypal_email] => ab2#sandbox.com
[vendor_id] => 2
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
)
[tv3#sandbox.com] => Array
(
[0] => Array
(
[name] => Polo
[product_id] => 353
[variation_id] => 0
[subtotal] => 80
[total] => 80
[quantity] => 4
[subtotal_tax] => 7.10
[total_tax] => 7.10
[paypal_email] => tv3#sandbox.com
[vendor_id] => 8
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
[1] => Array
(
[name] => Product From Test Vendor 3
[product_id] => 145
[variation_id] => 0
[subtotal] => 60
[total] => 60
[quantity] => 3
[subtotal_tax] => 5.33
[total_tax] => 5.33
[paypal_email] => tv3#sandbox.com
[vendor_id] => 10
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
)
[tv1#sandbox.com] => Array
(
[0] => Array
(
[name] => Product From Vendor 1
[product_id] => 143
[variation_id] => 0
[subtotal] => 20
[total] => 20
[quantity] => 2
[subtotal_tax] => 1.78
[total_tax] => 1.78
[paypal_email] => tv1#sandbox.com
[vendor_id] => 8
[shipping] => Array
(
[shipping_total] => 25.00
[shipping_tax] => 2.22
)
)
)
)
How can I do that?
Thanks
$orders = [.....]; //your array
$mappedOrders = [];
foreach($orders as $order) {
$mail = $order['paypal_email'];
if(!isset($mappedOrders[$mail])) { $mappedOrders[$mail] = []; } //create new array in map if $mail index not exists
$mappedOrders[$mail][] = $order; // push order into array for mapped array
}
var_dump($mappedOrders);
Do a loop with array key checking
$result = [];
foreach ($array as $value) {
$email = $value['paypal_email']; // Get email
if (!array_key_exists($email, $result)) { // Check if already on the result array
$result[$email] = []; // Create new array with email as key if not
}
$result[$email][] = $value; // push value to email key
}
print_r($result);
Consider first array hold by variable $array. Then iterate it with simple foreach loop and transfer data to new array $newArray with key as value in paypal_email node. Code should be:
$newArray = [];
foreach ($array as $value) {
$newArray[$value['paypal_email']][] = $value;
}
print_r($newArray);
<?php
$data =
[
[
'name' => 'John',
'email' => 'thebeatles#example.com'
],
[
'name' => 'Ringo',
'email' => 'thebeatles#example.com'
],
[
'name' => 'Mick',
'email' => 'thestones#example.com'
],
[
'name' => 'Keith',
'email' => 'thestones#example.com'
],
];
$grouped_by_email = [];
foreach($data as $item)
$grouped_by_email[$item['email']][] = $item;
var_export($grouped_by_email);
Output:
array (
'thebeatles#example.com' =>
array (
0 =>
array (
'name' => 'John',
'email' => 'thebeatles#example.com',
),
1 =>
array (
'name' => 'Ringo',
'email' => 'thebeatles#example.com',
),
),
'thestones#example.com' =>
array (
0 =>
array (
'name' => 'Mick',
'email' => 'thestones#example.com',
),
1 =>
array (
'name' => 'Keith',
'email' => 'thestones#example.com',
),
),
)
hope you are fine today.
I have an xml file online that I stored it into an array using file_get_contents(), simplexml_load_string() json_encode and json_decode; using the above methods gave an array like this:
[data] => Array
(
[transaction] => Array
(
[0] => Array
(
[fields] => Array
(
[transactionid] => 90397725
[transactionreference] => 90397725
[transactiontime] => 14:34:56
[transactiondate] => 2016-04-08
[upgauthcode] => 649192
[cardnumber] => ***************5104
[cardholdersname] => MISS Jane K Doe
[switchnumber] => Array
(
)
[cardstartyear] => 15
[cardstartmonth] => 02
[cardexpireyear] => 20
[cardexpiremonth] => 02
[transactionamount] => 108.00
[cardtype] => VISADEBIT
[baskettype] => order
[regisalu] => Miss
[regifnam] => Jane
[regilnam] => Doe
[regiadd1] => 14 Test Street
[regiadd4] => Test
[regiadd5] => West Test
[regiadd6] => fg28 5nZ
[regiadd7] => United Kingdom
[regidnum] => 07464000000
[regienum] => 07464000000
[regimobi] => 07464000000
[maddsalu] => Miss
[maddfnam] => Jane
[maddlnam] => Doe
[maddadd1] => 14 Test Street
[maddadd4] => Test
[maddadd5] => West Test
[maddadd6] => fg28 5nZ
[maddadd7] => United Kingdom
[madddnum] => 07464000000
[maddenum] => 07464000000
[maddidel] => Deliver
[baskettotal] => 90.00
[hirewaivertotal] => 0.00
[deliverytotal] => 0.00
[collectiontotal] => 0.00
[cardholderaddr1] => 14 Test Street
[cardholderaddr2] => Array
(
)
[cardholdercity] => Test
[cardholderstate] => West Test
[cardholderpostcode] => fg28 5nZ
[cardholdercountry] => United Kingdom
[regiuser] => jane.doe#gmail.com
[regihtml] => 0
[regigrde] => 0
[regigrdn] => 0
[regipopt] => 0
[maddcoll] => 1
[maddgrde] => 0
[maddgrdn] => 0
)
[orderitems] => Array
(
[item] => Array
(
[code] => DL008
[sku] => Array
(
)
[desc] => 22M LED Festoon (230v)
[description] => DL008, 22M LED Festoon (230v)
[price] => 45.00
[qty] => 2
[totalprice] => 90.00
)
)
)
[45] => Array
(
[fields] => Array
(
[transactionid] => 93645131
[transactionreference] => 93645131
[transactiontime] => 14:15:16
[transactiondate] => 2016-07-07
[upgauthcode] => 085526
[cardnumber] => ***************0103
[cardholdersname] => John Doe
[switchnumber] => Array
(
)
[cardstartyear] => 15
[cardstartmonth] => 12
[cardexpireyear] => 18
[cardexpiremonth] => 11
[transactionamount] => 588.00
[cardtype] => MASTERCARD
[baskettype] => order
[regisalu] => Mr
[regifnam] => John
[regilnam] => Doe
[regiadd1] => 39-45 TEST SQUARE
[regiadd2] => CITY Test Aquarium
[regiadd4] => London
[regiadd6] => bb2A 1op
[regiadd7] => United Kingdom
[regidnum] => 074640000000
[regienum] => 074640000000
[regimobi] => 07464000000
[maddsalu] => Mr
[maddfnam] => John
[maddlnam] => Doe
[maddadd1] => 39-45 TEST SQUARE
[maddadd2] => CITY Test AQUARIUM
[maddadd4] => London
[maddadd6] => bb2A 1op
[maddadd7] => United Kingdom
[madddnum] => 07464000000
[maddenum] => 07464000000
[maddidel] => Deliver
[baskettotal] => 490.00
[hirewaivertotal] => 0.00
[deliverytotal] => 0.00
[collectiontotal] => 0.00
[cardholderaddr1] => 39-45 TEST SQUARE
[cardholderaddr2] => CITY TEST AQUARIUM
[cardholdercity] => London
[cardholderpostcode] => bb2A 1op
[cardholdercountry] => United Kingdom
[regiuser] => john.doe#bloomberg.net
[regihtml] => 0
[regipopt] => 1
[regigrde] => 0
[regigrdn] => 0
[maddcoll] => 1
[maddgrde] => 0
[maddgrdn] => 0
)
[orderitems] => Array
(
[item] => Array
(
[0] => Array
(
[code] => PK289
[sku] => Array
(
)
[desc] => EvoLite Helmet STD Peak (white)
[description] => PK289, EvoLite Helmet STD Peak (white)
[price] => 9.00
[qty] => 6
[totalprice] => 54.00
)
[1] => Array
(
[code] => GGE3
[sku] => Array
(
)
[desc] => Graft Gear Safety Spectacle
[description] => GGE3, Graft Gear Safety Spectacle
[price] => 2.00
[qty] => 6
[totalprice] => 12.00
)
[2] => Array
(
[code] => GG025
[sku] => Array
(
)
[desc] => Graft Gear Hi-Vis Vest (M)
[description] => GG025, Graft Gear Hi-Vis Vest (M)
[price] => 5.00
[qty] => 2
[totalprice] => 10.00
)
[3] => Array
(
[code] => GG027
[sku] => Array
(
)
[desc] => Graft Gear Hi-Vis Vest (XL)
[description] => GG027, Graft Gear Hi-Vis Vest (XL)
[price] => 5.00
[qty] => 4
[totalprice] => 20.00
)
[4] => Array
(
[code] => GG029
[sku] => Array
(
)
[desc] => Graft Gear Hi-Vis Vest (3XL)
[description] => GG029, Graft Gear Hi-Vis Vest (3XL)
[price] => 5.00
[qty] => 4
[totalprice] => 20.00
)
[5] => Array
(
[code] => GG030
[sku] => Array
(
)
[desc] => Graft Gear Hi-Vis Vest (4XL)
[description] => GG030, Graft Gear Hi-Vis Vest (4XL)
[price] => 5.00
[qty] => 2
[totalprice] => 10.00
)
[6] => Array
(
[code] => GG037
[sku] => Array
(
)
[desc] => Graft Gear Bomber (M)
[description] => GG037, Graft Gear Bomber (M)
[price] => 23.00
[qty] => 1
[totalprice] => 23.00
)
[7] => Array
(
[code] => GG039
[sku] => Array
(
)
[desc] => Graft Gear Bomber (XL)
[description] => GG039, Graft Gear Bomber (XL)
[price] => 23.00
[qty] => 2
[totalprice] => 46.00
)
[8] => Array
(
[code] => GG041
[sku] => Array
(
)
[desc] => Graft Gear Bomber (XXXL)
[description] => GG041, Graft Gear Bomber (XXXL)
[price] => 23.00
[qty] => 3
[totalprice] => 69.00
)
[9] => Array
(
[code] => GG073
[sku] => Array
(
)
[desc] => Nubuck Mid-Cut Safety Boot
[description] => GG073, Nubuck Mid-Cut Safety Boot
[price] => 39.00
[qty] => 1
[totalprice] => 39.00
)
[10] => Array
(
[code] => GG071
[sku] => Array
(
)
[desc] => Nubuck Mid-Cut Safety Boot
[description] => GG071, Nubuck Mid-Cut Safety Boot
[price] => 39.00
[qty] => 2
[totalprice] => 78.00
)
[11] => Array
(
[code] => GG070
[sku] => Array
(
)
[desc] => Nubuck Mid-Cut Safety Boot
[description] => GG070, Nubuck Mid-Cut Safety Boot
[price] => 39.00
[qty] => 2
[totalprice] => 78.00
)
[12] => Array
(
[code] => PK454
[sku] => Array
(
)
[desc] => Ladies Black Hiker Boot
[description] => PK454, Ladies Black Hiker Boot
[price] => 31.00
[qty] => 1
[totalprice] => 31.00
)
)
)
)
)
)
)
Now I want to loop through that array, as I want to re-convert it into my XML format, I am able to access the first level of the array and the orderitems -> item -> code where the client purchased one single item, but I am not able to loop inside deeper level where the client purchased more than one item (second array)
here is my code
foreach($array['data']['transaction'] as $transaction){
//echo $transaction['fields']['transactionid']."<br>";
//echo $transaction['orderitems']['item']['code']."<br>";
if(isset($transaction['orderitems']['item']['code'])){
echo $transaction['orderitems']['item']['code']."<br>";
} else {
foreach($transaction['orderitems']['item'] as $multi_item){
echo "<--- MULTI ---><br>";
//tried so many things and none has worked;
//like $multi_item['code'];
}
}
}
how to access the code of each item purchased by john doe?
You can access this data by filtering the array.
In PHP >= 5.5.0 you can make a search like this;
$key = array_search('John Doe', array_column($yourArray, 'cardholdersname'));
This method will return the array that matched given criteria.
http://php.net/manual/tr/function.array-search.php
I am trying to fetch data using the following link:- https://dev.fitbit.com/docs/activity/ and API :- GET https://api.fitbit.com/1/user/[user-id]/activities/date/[date].json and getting response array as below
Array(
[result] => Array
(
[activities] => Array
(
[0] => Array
(
[activityId] => 90013
[activityParentId] => 90013
[activityParentName] => Walk
[calories] => 25
[description] => Walking less than 2 mph, strolling very slowly
[distance] => 0.271426
[duration] => 355000
[hasStartTime] => 1
[isFavorite] =>
[lastModified] => 2016-11-29T19:11:42.000Z
[logId] => 5007419020
[name] => Walk
[startDate] => 2016-11-30
[startTime] => 00:34
[steps] => 342
)
)
[goals] => Array
(
[activeMinutes] => 30
[caloriesOut] => 2157
[distance] => 8.05
[floors] => 10
[steps] => 10000
)
[summary] => Array
(
[activeScore] => -1
[activityCalories] => 55
[caloriesBMR] => 1257
[caloriesOut] => 1300
[distances] => Array
(
[0] => Array
(
[activity] => Walk
[distance] => 0.271426
)
[1] => Array
(
[activity] => total
[distance] => 0.48
)
[2] => Array
(
[activity] => tracker
[distance] => 0.42
)
[3] => Array
(
[activity] => loggedActivities
[distance] => 0.271426
)
[4] => Array
(
[activity] => veryActive
[distance] => 0.09
)
[5] => Array
(
[activity] => moderatelyActive
[distance] => 0.11
)
[6] => Array
(
[activity] => lightlyActive
[distance] => 0.16
)
[7] => Array
(
[activity] => sedentaryActive
[distance] => 0.12
)
)
[elevation] => 0
[fairlyActiveMinutes] => 5
[floors] => 0
[heartRateZones] => Array
(
[0] => Array
(
[caloriesOut] => 37.9099
[max] => 98
[min] => 30
[minutes] => 25
[name] => Out of Range
)
[1] => Array
(
[caloriesOut] => 33.193
[max] => 137
[min] => 98
[minutes] => 9
[name] => Fat Burn
)
[2] => Array
(
[caloriesOut] => 0
[max] => 166
[min] => 137
[minutes] => 0
[name] => Cardio
)
[3] => Array
(
[caloriesOut] => 0
[max] => 220
[min] => 166
[minutes] => 0
[name] => Peak
)
)
[lightlyActiveMinutes] => 6
[marginalCalories] => 33
[sedentaryMinutes] => 1426
[steps] => 789
[veryActiveMinutes] => 3
)
)
[code] => 200
[content_type] => application/json;charset=UTF-8
)
but the problem is this array just provides me the data of the activity that has been done using Fitbit application. But I have to fetch complete data whether its by the Fitbit application or Fitbit device i.e blaze.
Just glancing at the API, I believe you need to use activities/tracker/. The API states that this represents the daily activity values logged by the tracker device only, excluding manual activity log entries. So you just need to add tracker to your GET.
Tracker Activities:
activities/tracker/calories
activities/tracker/steps
activities/tracker/distance
activities/tracker/floors
activities/tracker/elevation
activities/tracker/minutesSedentary
activities/tracker/minutesLightlyActive
activities/tracker/minutesFairlyActive
activities/tracker/minutesVeryActive
activities/tracker/activityCalories
Array
(
[0] => Array
(
[Product] => Array
(
[id] => 5
[user_id] => 5
[category_id] => 1
[name] => Suger
[weight] => 1
[measurement] => kg
[image] =>
[status] => 1
[created] => 2015-05-29 17:02:25
[updated] => 0000-00-00 00:00:00
)
[Category] => Array
(
[id] => 1
[user_id] => 1
[category_name] => Daily uses
[category_image] =>
[status] => 1
[created] => 2015-05-25 12:56:10
[updated] => 2015-06-25 10:27:40
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 23
[product_id] => 5
[store_id] => 2
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435055384
[updated] => 1435055384
)
[1] => Array
(
[id] => 28
[product_id] => 5
[store_id] => 1
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435062129
[updated] => 1435062129
)
)
)
[1] => Array
(
[Product] => Array
(
[id] => 6
[user_id] => 1
[category_id] => 1
[name] => Tea
[weight] => 1
[measurement] => litre
[image] =>
[status] => 1
[created] => 2015-05-29 17:02:48
[updated] => 2015-06-18 18:53:30
)
[Category] => Array
(
[id] => 1
[user_id] => 1
[category_name] => Daily uses
[category_image] =>
[status] => 1
[created] => 2015-05-25 12:56:10
[updated] => 2015-06-25 10:27:40
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 22
[product_id] => 6
[store_id] => 2
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435055076
[updated] => 1435055076
)
[1] => Array
(
[id] => 25
[product_id] => 6
[store_id] => 1
[details] =>
[mrp] => 12
[selling_price] => 12
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435059905
[updated] => 1435059905
)
)
)
[5] => Array
(
[Product] => Array
(
[id] => 11
[user_id] => 2
[category_id] => 13
[name] => Real Mix Fruit Juice
[weight] => 200
[measurement] => litre
[image] =>
[status] => 1
[created] => 2015-06-17 12:03:19
[updated] => 2015-06-18 13:05:16
)
[Category] => Array
(
[id] => 13
[user_id] => 2
[category_name] => Soft Drink juices
[category_image] =>
[status] => 1
[created] => 2015-06-17 11:15:33
[updated] => 2015-06-18 18:46:03
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 2
[product_id] => 11
[store_id] => 2
[details] => Real Mix Fruit Juice(200 litre)
[mrp] => 20
[selling_price] => 18
[discount] => 10
[price_difference] => 2
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1434613767
[updated] => 1434613767
)
[1] => Array
(
[id] => 29
[product_id] => 11
[store_id] => 1
[details] => Real Mix Fruit Juice
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435062192
[updated] => 1435123348
)
)
)
[8] => Array
(
[Product] => Array
(
[id] => 14
[user_id] => 2
[category_id] => 13
[name] => Real Apple Juice
[weight] => 1
[measurement] => ml
[image] =>
[status] => 1
[created] => 2015-06-18 13:06:44
[updated] => 0000-00-00 00:00:00
)
[Category] => Array
(
[id] => 13
[user_id] => 2
[category_name] => Soft Drink juices
[category_image] =>
[status] => 1
[created] => 2015-06-17 11:15:33
[updated] => 2015-06-18 18:46:03
)
[Storeproduct] => Array
(
[0] => Array
(
[id] => 24
[product_id] => 14
[store_id] => 2
[details] =>
[mrp] => 10
[selling_price] => 10
[discount] => 0
[price_difference] => 0
[is_deal] => 0
[deal_start_date] =>
[deal_end_date] =>
[status] => 1
[created] => 1435055411
[updated] => 1435055411
)
)
)
)
In the above array there are two same category array .I would like merge the same category array records
I need a output like
Category => array(
//category data,
Products=>array(//product data,
Storeproducts =>array(
//Storeproducts data
)
)
)
PHP is pretty well documented and you can find all of the Array sorting methods on this page.
There are some good examples in the comments as well - all you need to do is to sort the array by category and you are done.
Hi my zend paginator works well when the $business_list array format is like below.
but when the array format changes it displays only one page instead of many pages.
$paginator = Zend_Paginator::factory($business_list);
Array
(
[0] => Array
(
[id] => 216
[userid] => 141
[title] => first req
[image] =>
[logo] =>
[description] =>
this is the first requirment
[date] => 2012-06-12 10:31:01
[area] => 1
[budget] => 1
[type] => 1
[status] => 1
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 315
[business_id] => 216
[section_id] => 1
[subsection_id] => 13
[description] =>
)
[1] => Array
(
[id] => 316
[business_id] => 216
[section_id] => 3
[subsection_id] => 14
[description] =>
)
[2] => Array
(
[id] => 317
[business_id] => 216
[section_id] => 4
[subsection_id] => 15
[description] =>
)
)
[CmUser] => Array
(
[id] => 141
[username] => venki
[password] =>
[firstname] => venkatesh
[lastname] => abus
[image] => 54winter.jpg
[email] => xxx#xx.com
[phone] => 23423452
[group_id] => 2
[status] =>
[registered_date] => 2012-06-04 06:32:58
[last_visit] => 0000-00-00 00:00:00
[is_active] => 1
[subscribe] => 1
)
)
[1] => Array
(
[id] => 214
[userid] => 98
[title] => gopicontractor
[image] => 54bluehills.jpg
[logo] => 239waterlilies.jpg
[description] =>
TIt uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is
[date] => 2012-06-11 12:18:58
[area] => 1
[budget] => 1
[type] => 3
[status] => 1
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 305
[business_id] => 214
[section_id] => 1
[subsection_id] => 5
[description] =>
)
[1] => Array
(
[id] => 306
[business_id] => 214
[section_id] => 1
[subsection_id] => 6
[description] =>
)
[2] => Array
(
[id] => 307
[business_id] => 214
[section_id] => 3
[subsection_id] => 1
[description] =>
)
[3] => Array
(
[id] => 308
[business_id] => 214
[section_id] => 4
[subsection_id] => 9
[description] =>
)
)
[CmUser] => Array
(
[id] => 98
[username] => gopi.s
[password] =>
[firstname] => venkatesh
[lastname] => franc
[image] =>
[email] => ss#ss.com
[phone] => 23423452
[group_id] => 3
[status] =>
[registered_date] => 2012-05-16 12:36:57
[last_visit] => 0000-00-00 00:00:00
[is_active] => 1
[subscribe] => 1
)
)
)
the above array format displays paginatin correctly.
This is the array that displays only one page in pagination.
Zend_Paginator Object
(
[_cacheEnabled:protected] => 1
[_adapter:protected] => Zend_Paginator_Adapter_Array Object
(
[_array:protected] => Array
(
[0] => Array
(
[id] => 89
[username] => xx
[password] => xx
[firstname] => xx
[lastname] => xx
[image] =>
[email] => xx#ymail.com
[phone] => 2342345
[group_id] => 2
[status] => offline
[registered_date] => 2012-05-15 10:58:53
[last_visit] =>
[is_active] => 1
[subscribe] => 0
[CmBusiness] => Array
(
[0] => Array
(
[id] => 204
[userid] => 89
[title] => xxhousing
[image] => 760067.jpg
[logo] => xx_818f3c97e6_o.jpg
[description] => xx
[date] => 2012-05-31 13:36:17
[area] => 1
[budget] => 1
[type] => 1
[status] => 1
[CmAmount] => Array
(
[id] => 1
[amount] => 1000-1500
[status] => 1
)
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 251
[business_id] => 204
[section_id] => 1
[subsection_id] => 6
[description] => xx
)
[1] => Array
(
[id] => 252
[business_id] => 204
[section_id] => 3
[subsection_id] => 2
[description] => xx
)
[2] => Array
(
[id] => 253
[business_id] => 204
[section_id] => 3
[subsection_id] => 4
[description] => xx
)
[3] => Array
(
[id] => 254
[business_id] => 204
[section_id] => 4
[subsection_id] => 9
[description] => xx
)
)
[CmArea] => Array
(
[id] => 1
[area] => manchester
[status] => 1
)
[CmType] => Array
(
[id] => 1
[type] => Personal business
[status] => 1
)
)
[1] => Array
(
[id] => 205
[userid] => 89
[title] => xx
[image] => 41217850-desktop-wallpapers-new-windows-xp.jpg
[logo] => 356anger_n.jpg
[description] => xx
[date] => 2012-05-31 13:37:15
[area] => 1
[budget] => 1
[type] => 3
[status] => 1
[CmAmount] => Array
(
[id] => 1
[amount] => 1000-1500
[status] => 1
)
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 255
[business_id] => 205
[section_id] => 1
[subsection_id] => 6
[description] =>xx
)
[1] => Array
(
[id] => 256
[business_id] => 205
[section_id] => 3
[subsection_id] => 1
[description] => xx
)
[2] => Array
(
[id] => 257
[business_id] => 205
[section_id] => 3
[subsection_id] => 2
[description] => xx
)
[3] => Array
(
[id] => 258
[business_id] => 205
[section_id] => 4
[subsection_id] => 10
[description] => xx
)
)
[CmArea] => Array
(
[id] => 1
[area] => manchester
[status] => 1
)
[CmType] => Array
(
[id] => 3
[type] => Bilde companies
[status] => 1
)
)
[2] => Array
(
[id] => 206
[userid] => 89
[title] => Nuestros recursos
[image] =>
[logo] =>
[description] => xx
[date] => 2012-05-31 13:38:04
[area] => 1
[budget] => 1
[type] => 4
[status] => 1
[CmAmount] => Array
(
[id] => 1
[amount] => 1000-1500
[status] => 1
)
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 259
[business_id] => 206
[section_id] => 1
[subsection_id] => 5
[description] =>
)
[1] => Array
(
[id] => 260
[business_id] => 206
[section_id] => 1
[subsection_id] => 6
[description] =>
)
[2] => Array
(
[id] => 261
[business_id] => 206
[section_id] => 3
[subsection_id] => 2
[description] =>
)
[3] => Array
(
[id] => 262
[business_id] => 206
[section_id] => 4
[subsection_id] => 10
[description] =>
)
)
[CmArea] => Array
(
[id] => 1
[area] => manchester
[status] => 1
)
[CmType] => Array
(
[id] => 4
[type] => Designer
[status] => 1
)
)
)
)
)
[_count:protected] => 1
)
[_currentItemCount:protected] =>
[_currentItems:protected] =>
[_currentPageNumber:protected] => 1
[_filter:protected] =>
[_itemCountPerPage:protected] => 2
[_pageCount:protected] => 1
[_pageRange:protected] =>
[_pages:protected] =>
[_view:protected] =>
)