I have the following array:
Cart Object
(
[event_list] => Array
(
[15] => stdClass Object
(
[event_id] => 15
[event_name] => North Pole Express 2014
[event_date] => 2014-12-06
[event_time] => 10:40:00
[event_ort_id] => 1
[ort_name] => Tanfield Railway
[ort_city] => Newcastle upon Tyne
[event_order_limit] => 0
[event_use_alt] =>
)
[14] => stdClass Object
(
[event_id] => 14
[event_name] => North Pole Express 2014
[event_date] => 2014-11-30
[event_time] => 10:40:00
[event_ort_id] => 1
[ort_name] => Tanfield Railway
[ort_city] => Newcastle upon Tyne
[event_order_limit] => 0
[event_use_alt] =>
)
[13] => stdClass Object
(
[event_id] => 13
[event_name] => North Pole Express 2014
[event_date] => 2014-11-29
[event_time] => 10:40:00
[event_ort_id] => 1
[ort_name] => Tanfield Railway
[ort_city] => Newcastle upon Tyne
[event_order_limit] => 0
[event_use_alt] =>
)
)
[cat_list] => Array
(
[138] => stdClass Object
(
[cat_id] => 138
[category_event_id] => 15
[cat_name] => Child - 4:00 pm
[cat_price] => 12.00
[cat_numbering] => none
)
[120] => stdClass Object
(
[cat_id] => 120
[category_event_id] => 14
[cat_name] => Child - 4:00 pm
[cat_price] => 12.00
[cat_numbering] => none
)
[102] => stdClass Object
(
[cat_id] => 102
[category_event_id] => 13
[cat_name] => Child - 4:00 pm
[cat_price] => 12.00
[cat_numbering] => none
)
)
[disc_list] => Array
(
)
[items] => Array
(
[4] => PlaceItem Object
(
[id] => 4
[cart] => Cart Object
*RECURSION*
[event_id] => 14
[category_id] => 120
[seats] => Array
(
[26151] => stdClass Object
(
[seat_id] => 26151
[seat_row_nr] => 0
[seat_nr] => 0
[seat_ts] => 1388769219
[discount_id] => 0
)
)
[ts] =>
[created] => 2014-01-03T16:43:39+00:00
[expired] =>
)
)
[ts] => 1388769219
)
I need to be able to access the 'Items' Key.
However everything I have tried so far has failed. I suspect I am missing something really obvious.
What would be the best way to access these items?
Cart is not an array, it's an Object.
$cart = new Cart();
$cart->items; // <-- this is an array (of PlaceItems)
Since $cart is an object you need to use object notation to access it, the arrays are underneath that:
forach ($cart->items as $key=>$value) {
//...
}
Update from your comment:
$items=$_SESSION['_SMART_cart']->items;
foreach ($items as $key=>$value) {
//...
}
Related
I'm using Laravel and I wonder how can I put this array in a foreach? for read it
stdClass Object ( [data] => Array ( [0] => stdClass Object ( [id] => 0001 [type] => Item [attributes] => stdClass Object ( [product_name] => ST Slotted Sport Brake Rotors [part_number] => st126.39027SL [mfr_part_number] => 126.39027SL [part_description] => StopTech Power Slot 00-04 Volvo S40/V40 Front Left Slotted Rotor [category] => Brakes, Rotors & Pads [subcategory] => Brake Rotors - Slotted [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 15 [width] => 15 [height] => 4 [weight] => 12 ) ) [brand_id] => 56 [brand] => Stoptech [price_group_id] => 129 [price_group] => Stoptech [active] => 1 [regular_stock] => [dropship_controller_id] => 19 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d5otzd52uv6zz.cloudfront.net/fa33cfb5-0c91-47de-9a49-67f4175a5bff-100.jpg [barcode] => 805890204282 ) ) [1] => stdClass Object ( [id] => 078595 [type] => Item [attributes] => stdClass Object ( [product_name] => RAD Clutch Fork Stop [part_number] => rad20-0262 [mfr_part_number] => 20-0262 [part_description] => Radium Engineering Mitsubishi Evo 8-10 Clutch Fork Stop [category] => Drivetrain [subcategory] => Clutch Uncategorized [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 4.75 [width] => 4.5 [height] => 4.5 [weight] => 0.5 ) ) [brand_id] => 148 [brand] => Radium Engineering [price_group_id] => 406 [price_group] => Radium Engineering [active] => 1 [regular_stock] => 1 [dropship_controller_id] => 81 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d32vzsop7y1h3k.cloudfront.net/adb8244ed2d562e078c5ce2928750f2a.JPG ) ) [2] => stdClass Object ( [id] => 095906 [type] => Item [attributes] => stdClass Object ( [product_name] => MLR Trans Rebuild Kits [part_number] => mlr88075K [mfr_part_number] => 88075K [part_description] => McLeod Performance Transmission Rebuild Kit w/ Kolene Steels 4L80E 1997-2011 - Stage 1 [category] => Drivetrain [subcategory] => Transmission Rebuild Kits [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 24 [width] => 16 [height] => 5.25 [weight] => 14.75 ) ) [brand_id] => 169 [brand] => McLeod Racing [price_group_id] => 456 [price_group] => McLeod Racing [active] => 1 [regular_stock] => [dropship_controller_id] => 116 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) ) ) [3] => stdClass Object ( [id] => 1 [type] => Item [attributes] => stdClass Object ( [product_name] => TXS Boost Controllers [part_number] => txs-BC-HPBC [mfr_part_number] => txs-BC-HPBC [part_description] => Turbo XS High Performance Boost Controller [category] => Forced Induction [subcategory] => Boost Controllers [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 4.75 [width] => 3.25 [height] => 2.25 [weight] => 0.5 ) ) [brand_id] => 63 [brand] => Turbo XS [price_group_id] => 130 [price_group] => Turbo XS [active] => 1 [regular_stock] => 1 [dropship_controller_id] => 0 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d5otzd52uv6zz.cloudfront.net/92670bde-a650-4ae6-a53e-0da8b2a26d1c-100.jpg [barcode] => 053176487038 ) )
Thanks!
Just loop through your data with
foreach($yourvar->data as $key=> $data){
echo $data->id;
}
If you get an StdClass object it means you're iterating over an object through -> if you've an array you can print through $data['key']
Hello I am using PHP driver for MongoDB and MY Array is something like this
stdClass Object
(
[_id] => stdClass Object
(
[$id] => 58e0af1b9c76847c7e8b4567
)
[prod_details] => stdClass Object
(
[1] => stdClass Object
(
[1] => stdClass Object
(
[prod_id] => 1
[asin] => xxxxxx
[sku] => 1
[prod_name] => Windows 98: Second Edition
[prod_price] => 13433
[prod_price_f] => 13433
[prod_currency] => INR
[prod_price_min] =>
[prod_price_max] =>
[prod_quantity] => 1
[prod_condition] => New
[prod_shipping] => 60.00
[prod_category] =>
[prod_added] =>
)
[11] => stdClass Object
(
[prod_id] => 11
[asin] => xxxxxxx
[sku] => 11
[prod_name] => The Coke Machine: The Dirty Truth Behind the World's Favorite Soft Drink [Paperback] [Sep 06, 2011] Blanding, Michael
[prod_price] => 2500
[prod_price_f] => 2500
[prod_currency] => INR
[prod_price_min] =>
[prod_price_max] =>
[prod_quantity] => 8
[prod_condition] => New
[prod_shipping] => 60.00
[prod_category] =>
[prod_added] =>
)
[12] => stdClass Object
(
[prod_id] => 12
[asin] => xxxxxxx
[sku] => 12
[prod_name] => In Other Words [Hardcover] [Feb 09, 2016] Jhumpa Lahiri
[prod_price] => 748.9
[prod_price_f] => 748.9
[prod_currency] => INR
[prod_price_min] =>
[prod_price_max] =>
[prod_quantity] => 8
[prod_condition] => New
[prod_shipping] => 60.00
[prod_category] =>
[prod_added] =>
)
when I run PHP query I get ALL result and not filtered result with skip and limit
$collection->find(array('_id'=>new MongoId($mongoid)), array('prod_details.1' => ''))->skip(0)->limit(2);
Here I am traversing to prod_details >> 1 and putting limit of 0 to 2 but I get all objects. and limit is not working.
Please help.
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
I created a model with 10 append attributes and I can't get them with find() method. But when I convert returned object from find() to an array with method toArray() I can see them but I need them like an object.
This object was printed when I use find():
School Object
(
[table:protected] => schools
[fillable:protected] => Array
(
[0] => name
[1] => type_id
[2] => description
[3] => info_specialties
[4] => contacts
[5] => cover_name
[6] => financing_id
[7] => city
)
[guarded:protected] => Array
(
[0] => id
)
[appends:protected] => Array
(
[0] => type
[1] => short_type
[2] => school_url
[3] => cover_photo_url
[4] => cover_photo_thumbnail_url
[5] => city
[6] => municipality
[7] => appended_district_id
[8] => district
[9] => description_without_tags
)
[district_id] =>
[cover_photo] =>
[connection:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 24
[type_id] => 3
[name] => adasdasd
[description] =>
asdadasdasdasdqwdqd\qw\[dqw\d
[info_specialties] =>
qwqwdqwdqwdqwdqwd
[contacts] =>
qwdqwdqwdqwd
[cover_name] => SAbjfpe4m7.jpg
[financing_id] => 1
[city_id] => 18
[created_at] => 2015-01-31 20:56:06
[updated_at] => 2015-02-04 18:50:13
)
[original:protected] => Array
(
[id] => 24
[type_id] => 3
[name] => adasdasd
[description] =>
asdadasdasdasdqwdqd\qw\[dqw\d
[info_specialties] =>
qwqwdqwdqwdqwdqwd
[contacts] =>
qwdqwdqwdqwd
[cover_name] => SAbjfpe4m7.jpg
[financing_id] => 1
[city_id] => 18
[created_at] => 2015-01-31 20:56:06
[updated_at] => 2015-02-04 18:50:13
)
[relations:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[dates:protected] => Array
(
)
[touches:protected] => Array
(
)
[observables:protected] => Array
(
)
[with:protected] => Array
(
)
[morphClass:protected] =>
[exists] => 1
)
And when I use toArray:
Array
(
[id] => 24
[type_id] => 3
[name] => adasdasd
[description] =>
asdadasdasdasdqwdqd\qw\[dqw\d
[info_specialties] =>
qwqwdqwdqwdqwdqwd
[contacts] =>
qwdqwdqwdqwd
[cover_name] => SAbjfpe4m7.jpg
[financing_id] => 1
[city_id] => 18
[created_at] => 2015-01-31 20:56:06
[updated_at] => 2015-02-04 18:50:13
[type] => qdasdasd
[short_type] => asdasdasd
[school_url] => http://localhost:8000/school/24
[cover_photo_url] => http://localhost:8000/storage/cover_photos/SAbjfpe4m7.jpg
[cover_photo_thumbnail_url] => http://localhost:8000/storage/cover_photos/thumbnails/SAbjfpe4m7.jpg
[city] => sdasdasd
[municipality] => ÐÑкаква община2 от нÑкакъв облаÑÑ‚2
[appended_district_id] => 6
[district] => ÐÑкакъв облаÑÑ‚2
[description_without_tags] => asdadasdasdasdqwdqd\qw\[dqw\d
)
Here's an example of my class:
<?php
class School extends Eloquent {
protected $appends = array('type');
public function getTypeAttribute()
{
return Type::find($this->type_id)->name;
}
}
That's the nature of custom attributes that you get with an attribute accessor. They will only be evaluated when used (and then cached for later use). When you convert it to and array, all $appends properties are loaded.
If you have your model object you can just access them like any other attribute:
$school->type;
In php I have an array look like this.
Array ( [0] =>
[1] => Array ([id] => 9 [slot] => 2 [name] => Test Ad [alt] => Test Ad [dimension_width] => 300 [dimension_height] => 400 [clicks] => 1 [start_date] => 06/07/2013 [end_date] => 07/07/2013 [status] => 1 [target] => http://images.google.com [image_url] => http://localhost/WebSites/coffee/wp-content/uploads/2013/06/uwp5-1-151553.jpeg [pre_exp_email] => 0 )
[2] => Array ( [id] => 12 [slot] => 1 [name] => Test Ad [alt] => Test Ad [dimension_width] => 200 [dimension_height] => 300 [clicks] => 0 [start_date] => 06/08/2013 [end_date] => 07/08/2013 [status] => 1 [target] => http://facebook.com [image_url] => http://localhost/WebSites/coffee/wp-content/uploads/2013/06/uwp5-1-1515532.jpeg [pre_exp_email] => 0 )
[3] => Array ( [id] => 14 [slot] => 1 [name] => Test Ad [alt] => Test Ad [dimension_width] => 200 [dimension_height] => 300 [clicks] => 0 [start_date] => 06/08/2013 [end_date] => 07/08/2013 [status] => 1 [target] => http://facebook.com [image_url] => http://localhost/WebSites/coffee/wp-content/uploads/2013/06/uwp5-1-1515532.jpeg [pre_exp_email] => 0 )
)
From here I want to get the first value of array. For example I want to get the value of first array
[1] => Array ([id] => 9 [slot] => 2 [name] => Test Ad [alt] => Test Ad [dimension_width] => 300 [dimension_height] => 400 [clicks] => 1 [start_date] => 06/07/2013 [end_date] => 07/07/2013 [status] => 1 [target] => http://images.google.com [image_url] => http://localhost/WebSites/coffee/wp-content/uploads/2013/06/uwp5-1-151553.jpeg [pre_exp_email] => 0 )
So can someone kindly tell me how to get the value of 1st array?Any help and suggestions will be really appreciable. Thanks
say all your array was in a variable $myArray, then
myArray[1]
will give you your first array