Array
(
[0] => stdClass Object
(
[id] => 7
[price] => 1300
[discount] => 13
[early_bird_date] => 2014-12-30
[timing] =>
[batch] =>
[slug] =>
[status] => 1
[ktw_course_id] => 5
[ktw_country_id] => 2
[ktw_city_id] => 5
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 3
[ktw_currency_id] => 6
[created] =>
[modified] =>
[course] => jquery
[country] => kuwait
[city] => dubai
[currency] => EUR
[workshop_dates] => Array
(
[0] => stdClass Object
(
[id] => 7
[start_date] => 2014-11-04
[end_date] => 2015-01-05
[status] => 1
[ktw_workshop_id] => 7
[created] => 2014-11-28 06:09:41
[modified] => 2014-11-28 06:09:41
)
[1] => stdClass Object
(
[id] => 8
[start_date] => 2015-01-06
[end_date] => 2015-01-07
[status] => 1
[ktw_workshop_id] => 7
[created] => 2014-11-28 06:09:55
[modified] => 2014-11-28 06:09:55
)
[2] => stdClass Object
(
[id] => 9
[start_date] => 2015-01-08
[end_date] => 2015-01-09
[status] => 1
[ktw_workshop_id] => 7
[created] => 2014-11-28 06:10:15
[modified] => 2014-11-28 06:10:15
)
)
)
[1] => stdClass Object
(
[id] => 5
[price] => 900
[discount] => 13
[early_bird_date] => 2014-11-26
[timing] =>
[batch] =>
[slug] =>
[status] => 1
[ktw_course_id] => 5
[ktw_country_id] => 1
[ktw_city_id] => 2
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 1
[ktw_currency_id] => 1
[created] =>
[modified] => 2014-11-14 14:34:29
[course] => jquery
[country] => india
[city] => vizag
[currency] => INR
[workshop_dates] => Array
(
[0] => stdClass Object
(
[id] => 2
[start_date] => 2014-11-28
[end_date] => 2014-11-29
[status] => 1
[ktw_workshop_id] => 5
[created] =>
[modified] =>
)
)
)
[2] => stdClass Object
(
[id] => 6
[price] => 1300
[discount] => 13
[early_bird_date] => 2014-12-30
[timing] =>
[batch] =>
[slug] =>
[status] => 1
[ktw_course_id] => 5
[ktw_country_id] => 1
[ktw_city_id] => 4
[ktw_timeslot_id] => 0
[ktw_training_mode_id] => 2
[ktw_currency_id] => 1
[created] =>
[modified] => 2014-11-25 10:16:58
[course] => jquery
[country] => india
[city] => hyderabad
[currency] => INR
[workshop_dates] => Array
(
[0] => stdClass Object
(
[id] => 4
[start_date] => 2014-12-30
[end_date] => 2014-12-31
[status] => 1
[ktw_workshop_id] => 6
[created] => 2014-11-28 06:08:44
[modified] => 2014-11-28 06:08:44
)
[1] => stdClass Object
(
[id] => 5
[start_date] => 2014-12-31
[end_date] => 2015-01-01
[status] => 1
[ktw_workshop_id] => 6
[created] => 2014-11-28 06:08:59
[modified] => 2014-11-28 06:08:59
)
[2] => stdClass Object
(
[id] => 6
[start_date] => 2015-01-02
[end_date] => 2015-01-03
[status] => 1
[ktw_workshop_id] => 6
[created] => 2014-11-28 06:09:14
[modified] => 2014-11-28 06:09:14
)
)
)
)
我想打印start_date并结束_date,请帮帮我怎样才能得到它。 提前谢谢。
答案 0 :(得分:1)
这是一个非常初学的问题。
foreach ($YourVariable as $arr_of_objs ) {
foreach ($arr_of_objs->workshop_dates as $obj) {
echo $obj->start_date;
echo $obj->end_date;
# code...
}
}
答案 1 :(得分:0)
假设对象正在实现ArrayAccess。你会这样做:
foreach ($object as $obj) {
foreach($obj[workshop_dates] as $workshopdate) {
$startDate = $workshopdate ['start_date'];
$endDate = $workshopdate ['end_date'];
}
}
答案 2 :(得分:0)
试试这个 -
$obj = //your object
$newArray = (array)$obj;//converting object to array
foreach ($newArray as $val) {
foreach ($val['workshop_dates'] as $value) {
echo $value['start_date']. ' ' .$value['end_date'];
}
}