Here i want to compare two array results where the results looks like this,array1 looks like this
array(7) { [0]=> string(6) "M" [1]=> string(7) "T" [2]=> string(9) "W" [3]=> string(8) "T" [4]=> string(6) "F" [5]=> string(8) "S" [6]=> string(6) "S" }
array2 looks like this
array(7) { [0]=> string(5) "15:00" [1]=> string(5) "14:00" [2]=> string(5) "13:00" [3]=> string(0) "" [4]=> string(5) "12:00" [5]=> string(5) "11:00" [6]=> string(5) "10:00" }
here i want to compare the first value of array1 with the first value of array2row with the second and if the value return true it should perform a function and if the value return empty it should perform another function
so i had done my code like this
<?php foreach($array1 as $index => $val)
{
foreach($array2 as $index2 => $val2){?>
//here i want to compare $val with $val2 to check $val2 is not empty or not
<?php }
}?>
You should do something like that:
$array1 = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
$array2 = array("15:00","14:00","13:00","", "12:00","11:00","10:00");
foreach($array1 as $index => $val) {
echo "compare $val to $array2[$index] <br />";
}
This code returns:
compare Monday to 15:00
compare Tuesday to 14:00
compare Wednesday to 13:00
compare Thursday to
compare Friday to 12:00
compare Saturday to 11:00
compare Sunday to 10:00
Related
I want to get hold of the value of DashboardCalc, which lies in the following array:
array(1) {
[0]=>
object(MatrixSubHeadline)#27226 (4) {
["schemaHeadline":"MatrixSubHeadline":private]=>
object(common_db_schemacontent)#28107 (12) {
["viewhelp":"common_db_schemacontent":private]=>
NULL
["unsavedTranslations"]=>
array(0) {
}
["objectLangCode":"common_translation_translateobject":private]=>
string(0) ""
["transUseFallback":"common_translation_translateobject":private]=>
bool(true)
["classData":protected]=>
array(15) {
["SchemaContentID"]=>
string(5) "15611"
["SchemaID"]=>
string(3) "132"
["IndexNo"]=>
string(1) "0"
["PageNo"]=>
string(1) "7"
["ContentType"]=>
string(8) "headline"
["QuestionID"]=>
string(1) "0"
["HeadlineContentID"]=>
string(1) "0"
["ImagePath"]=>
string(0) ""
["ThumbPath"]=>
string(0) ""
["Text"]=>
string(21) "Generelle kommentarer"
["ContentSettings"]=>
string(2) "[]"
["CreatedUserID"]=>
string(2) "15"
["CreatedTime"]=>
string(19) "2021-11-11 12:36:00"
["UpdatedUserID"]=>
string(2) "15"
["UpdatedTime"]=>
string(19) "2021-12-17 15:35:00"
}
["classChanges":protected]=>
array(0) {
}
["tableName":protected]=>
string(13) "schemacontent"
["primaryIDName":protected]=>
string(15) "SchemaContentID"
["cacheEnabled":protected]=>
bool(true)
["accountTable":protected]=>
bool(false)
["extraData":protected]=>
array(0) {
}
["saveError":"common_library_dbbase":private]=>
bool(false)
}
["questionList":"MatrixSubHeadline":private]=>
array(1) {
[0]=>
object(MatrixQuestion)#27225 (4) {
["content":"MatrixQuestion":private]=>
object(common_db_schemacontent)#28106 (12) {
["viewhelp":"common_db_schemacontent":private]=>
NULL
["unsavedTranslations"]=>
array(0) {
}
["objectLangCode":"common_translation_translateobject":private]=>
string(0) ""
["transUseFallback":"common_translation_translateobject":private]=>
bool(true)
["classData":protected]=>
array(15) {
["SchemaContentID"]=>
string(5) "15612"
["SchemaID"]=>
string(3) "132"
["IndexNo"]=>
string(1) "1"
["PageNo"]=>
string(1) "7"
["ContentType"]=>
string(8) "question"
["QuestionID"]=>
string(3) "923"
["HeadlineContentID"]=>
string(5) "15611"
["ImagePath"]=>
string(0) ""
["ThumbPath"]=>
string(0) ""
["Text"]=>
string(0) ""
["ContentSettings"]=>
string(21) "{"criteriaenabled":0}"
["CreatedUserID"]=>
string(2) "15"
["CreatedTime"]=>
string(19) "2021-11-11 12:36:00"
["UpdatedUserID"]=>
string(2) "15"
["UpdatedTime"]=>
string(19) "2021-12-17 15:35:00"
}
["classChanges":protected]=>
array(0) {
}
["tableName":protected]=>
string(13) "schemacontent"
["primaryIDName":protected]=>
string(15) "SchemaContentID"
["cacheEnabled":protected]=>
bool(true)
["accountTable":protected]=>
bool(false)
["extraData":protected]=>
array(0) {
}
["saveError":"common_library_dbbase":private]=>
bool(false)
}
["question":"MatrixQuestion":private]=>
object(common_db_question)#27289 (13) {
["schemaUsage":"common_db_question":private]=>
NULL
["viewHelper":"common_db_question":private]=>
NULL
["unsavedTranslations"]=>
array(0) {
}
["objectLangCode":"common_translation_translateobject":private]=>
string(0) ""
["transUseFallback":"common_translation_translateobject":private]=>
bool(true)
["classData":protected]=>
array(23) {
["QuestionID"]=>
string(3) "923"
["OwnerAccountID"]=>
string(1) "0"
["Question"]=>
string(21) "Generelle kommentarer"
["QuestionType"]=>
string(1) "5"
["Answers"]=>
string(178) "{"answers":null,"groupanswers":[{"count":"1","text":"Ja, jeg vil gerne tilf\u00f8je en generel kommentar","index":"0"}],"questions":["Har du andre kommentarer til din trivsel?"]}"
["SubText"]=>
string(59) "(Skriv dine kommentarer ved at trykke på kommentar-ikonet)"
["AllowOther"]=>
string(1) "0"
["MixAnswers"]=>
string(1) "0"
["MustAnswer"]=>
string(1) "0"
["MinAnswers"]=>
string(1) "0"
["MaxAnswers"]=>
string(1) "0"
["Columns"]=>
string(1) "1"
["OtherText"]=>
string(0) ""
["CreatedUserID"]=>
string(2) "15"
["CreatedTime"]=>
string(19) "2021-11-11 12:36:00"
["UpdatedUserID"]=>
string(2) "15"
["UpdatedTime"]=>
string(19) "2021-11-11 12:44:00"
["DashboardShow"]=>
string(1) "0"
["DashboardCalc"]=>
string(1) "0"
["QuestionTags"]=>
string(1) "0"
["UseComment"]=>
string(1) "1"
["IsPublic"]=>
string(1) "0"
["StdAnswer"]=>
string(1) "0"
}
["classChanges":protected]=>
array(0) {
}
["tableName":protected]=>
string(8) "question"
["primaryIDName":protected]=>
string(10) "QuestionID"
["cacheEnabled":protected]=>
bool(true)
["accountTable":protected]=>
bool(false)
["extraData":protected]=>
array(0) {
}
["saveError":"common_library_dbbase":private]=>
bool(false)
}
["text":"MatrixQuestion":private]=>
string(41) "Har du andre kommentarer til din trivsel?"
["index":"MatrixQuestion":private]=>
int(0)
}
}
["questionMap":"MatrixSubHeadline":private]=>
array(1) {
[15612]=>
array(1) {
[0]=>
int(0)
}
}
["useComments":"MatrixSubHeadline":private]=>
bool(true)
}
}
Please note: the array contains a few objects, which are private. I am not sure whether private objects can be accessed or not, or if the "private" is about the name, or the content.
The data is inherited from a database.
You can access object value by using loop iteration like this:
I am selecting here SchemaContentID, SchemaID and IndexNo.
{% for arrayObj in Objs %}
<ul>
<li>{{ Objs.SchemaContentID}}</li>
<li>{{ Objs.SchemaID}}</li>
<li>{{ Objs.IndexNo}}</li>
</ul>
{% endfor %}
thanks for checking out my question i have the following json data
array(568) {
[0]=>
array(11) {
["ID"]=>
string(6) "000001"
["Portrait"]=>
string(12) "BaseGoku.png"
["Name"]=>
string(42) "[The Saiyan who grew up on Earth] Son Goku"
["Series"]=>
string(11) "Dragon Ball"
["MaxRarity"]=>
string(6) "6 Star"
["Type"]=>
string(4) "Blue"
["Class"]=>
string(4) "Tank"
["Era"]=>
string(4) "1980"
["ReleaseDate"]=>
string(10) "2018-03-28"
["Farmable"]=>
string(1) "0"
["Method"]=>
string(17) "Trade Medal Store"
}
[1]=>
array(11) {
["ID"]=>
string(6) "000003"
["Portrait"]=>
string(8) "Goku.png"
["Name"]=>
string(8) "Son Goku"
["Series"]=>
string(11) "Dragon Ball"
["MaxRarity"]=>
string(6) "6 Star"
["Type"]=>
string(6) "Yellow"
["Class"]=>
string(3) "DPS"
["Era"]=>
string(4) "1980"
["ReleaseDate"]=>
string(10) "2018-03-28"
["Farmable"]=>
string(1) "0"
["Method"]=>
string(14) "Standard Gacha"
} etc
i have been tring to decode this and pull the data using a future
Future<Users> fetchInfo() async {
final response = await http.get(jsonplaceholder);
final jsonresponse = json.decode(response.body);
return Users.fromJson(jsonresponse[8]);
}
but i keep getting the error "Error FormatException: Unexpected character(at character 1) array(568)
not to sure what im doing wrong as i am new to flutter
any help would be appreciated thanks
heres the users model
class Users {
final int userID;
final String name;
final String portrait;
final String series;
Users({this.name, this.userID, this.portrait, this.series});
factory Users.fromJson(Map<String, dynamic> usersjson)=> Users(
name: usersjson["name"],
);
}
First of all are you sure this is the json data you're getting cause it should be like
[
{
"ID": "000001"
"Name": "[The Saiyan who grew up on Earth] Son Goku",
"Portrait": "BaseGoku.png",
"Series": "Dragon Ball",
"MaxRarity": "6 start",
"Type": "Blue",
"Class": "Tank",
"Era": "1980",
"Release Date": "2018-03-28",
"Farmable": "0",
"Method": "Trade Medal Store"
}
]
Flutter expects Map type for json.decode. If it's a public api can you please post it here.
I am using this function to return all available image size as array.
function king_image_size() {
$image_sizes = get_intermediate_image_sizes();
foreach ($image_sizes as $tax) {
$image_sizes[$tax] = $tax;
}
return $image_sizes
}
But this duplicates the return array. Output
array(18) { [0]=> string(9) "thumbnail" [1]=> string(6) "medium" [2]=> string(12) "medium_large" [3]=> string(5) "large" [4]=> string(9) "dhaka-por" [5]=> string(11) "dhaka-por-h" [6]=> string(15) "dhaka-landscape" [7]=> string(7) "dhaka-h" [8]=> string(8) "dhaka-sq" ["thumbnail"]=> string(9) "thumbnail" ["medium"]=> string(6) "medium" ["medium_large"]=> string(12) "medium_large" ["large"]=> string(5) "large" ["dhaka-por"]=> string(9) "dhaka-por" ["dhaka-por-h"]=> string(11) "dhaka-por-h" ["dhaka-landscape"]=> string(15) "dhaka-landscape" ["dhaka-h"]=> string(7) "dhaka-h" ["dhaka-sq"]=> string(8) "dhaka-sq" }
Anotherway that I found very common,
function king_image_size() {
$image_sizes = get_intermediate_image_sizes();
return $image_sizes;
}
Then I am getting 0,1,2,3... output in page builder. I need the function to work like
function king_image_size(){
return array(
'medium' => 'medium' ,
);
}
So you just want an array that uses the values you got, as the keys as well …?
For that, you can simply use array_combine, and just feed the value array in twice:
function king_image_size() {
$image_sizes = get_intermediate_image_sizes();
return array_combine($image_sizes, $image_sizes);
}
I have a nested foreach loop that iterates through classes and offerings. In one case, I have a Yoga class with two offerings; Session 1 and Session 2.
Signing up for a session means attending all dates.
Session 1 has 5 unique dates and Session 2 has 5 unique dates. Currently, my foreach loop shows each as it's own "offering":
Yoga
Session 1
10/1/16
5pm - 6pm
Session 1
10/8/16
3pm - 4pm
Session 1
10/11/16
10am - 11am
Session 1
10/12/16
10am - 11am
Session 1
10/15/16
4pm - 5p
Session 2
11/1/16
5pm - 6pm
Session 2
11/9/16
3pm - 4pm
Session 2
11/15/16
10am - 11am
Session 2
11/16/16
10am - 11am
Session 2
11/23/16
4pm - 5pm
so now I'm running into a problem. Perhaps I need another loop so the 5 unique dates get listed within each Session offering?
Session 1
10/1/16
5pm - 6pm
10/8/16
3pm - 4pm
10/11/16
10am - 11am
10/12/16
10am - 11am
10/15/16
4pm - 5pm
Session 2
11/1/16
5pm - 6pm
11/9/16
3pm - 4pm
11/15/16
10am - 11am
11/16/16
10am - 11am
11/23/16
4pm - 5pm
foreach ($rows as $row) {
if ($row['offering']=="Session 1"){
// do something
}
if ($row['offering']=="Session 2") {
// do something
}
}
tried this but it still shows all as individual rows
$array = array($row['offering']);
foreach ($array as $key => $val) {
// do stuff
echo $val;
}
}
I'm not on the right track...would appreciate some guidance.
A sample var_dump
["YOGA"]=> array(10) {
[0]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "0550AA8D-F437-4578-BD98-95C51D017E62" ["offering"]=> string(15) "YOGA Session 1" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "We" ["StartDate"]=> string(10) "10/05/2016" ["EndDate"]=> string(10) "10/05/2016" ["StartTime"]=> string(7) " 6:00PM" ["EndTime"]=> string(7) "10:00PM" ["Location"]=> string(23) "Off-Site, Quiet Room" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(1) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Sep 29 2016 12:00AM" }
[1]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "0550AA8D-F437-4578-BD98-95C51D017E62" ["offering"]=> string(15) "YOGA Session 1" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Su" ["StartDate"]=> string(10) "10/09/2016" ["EndDate"]=> string(10) "10/09/2016" ["StartTime"]=> string(7) " 9:00AM" ["EndTime"]=> string(7) " 5:00PM" ["Location"]=> string(8) "Off-Site" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(1) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Sep 29 2016 12:00AM" }
[2]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "0550AA8D-F437-4578-BD98-95C51D017E62" ["offering"]=> string(15) "YOGA Session 1" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "We" ["StartDate"]=> string(10) "10/12/2016" ["EndDate"]=> string(10) "10/12/2016" ["StartTime"]=> string(7) " 6:00PM" ["EndTime"]=> string(7) "10:00PM" ["Location"]=> string(13) "Quiet Room" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(1) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Sep 29 2016 12:00AM" }
[3]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "0550AA8D-F437-4578-BD98-95C51D017E62" ["offering"]=> string(15) "YOGA Session 1" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Sa" ["StartDate"]=> string(10) "10/15/2016" ["EndDate"]=> string(10) "10/15/2016" ["StartTime"]=> string(7) " 9:00AM" ["EndTime"]=> string(7) " 5:00PM" ["Location"]=> string(11) "YOGA Class" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(1) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Sep 29 2016 12:00AM" }
[4]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "0550AA8D-F437-4578-BD98-95C51D017E62" ["offering"]=> string(15) "YOGA Session 1" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Su" ["StartDate"]=> string(10) "10/16/2016" ["EndDate"]=> string(10) "10/16/2016" ["StartTime"]=> string(7) " 9:00AM" ["EndTime"]=> string(7) " 5:00PM" ["Location"]=> string(11) "YOGA Class" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(1) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Sep 29 2016 12:00AM" }
[5]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "DE7A6045-2908-47B6-AD13-6DC12FF42F6E" ["offering"]=> string(15) "YOGA Session 2" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Tu" ["StartDate"]=> string(10) "11/01/2016" ["EndDate"]=> string(10) "11/01/2016" ["StartTime"]=> string(7) " 6:00PM" ["EndTime"]=> string(7) "10:00PM" ["Location"]=> string(23) "Off-Site, Quiet Room" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(3) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Oct 26 2016 12:00AM" }
[6]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "DE7A6045-2908-47B6-AD13-6DC12FF42F6E" ["offering"]=> string(15) "YOGA Session 2" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Su" ["StartDate"]=> string(10) "11/06/2016" ["EndDate"]=> string(10) "11/06/2016" ["StartTime"]=> string(7) " 9:00AM" ["EndTime"]=> string(7) " 5:00PM" ["Location"]=> string(8) "Off-Site" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(3) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Oct 26 2016 12:00AM" }
[7]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "DE7A6045-2908-47B6-AD13-6DC12FF42F6E" ["offering"]=> string(15) "YOGA Session 2" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Tu" ["StartDate"]=> string(10) "11/08/2016" ["EndDate"]=> string(10) "11/08/2016" ["StartTime"]=> string(7) " 6:00PM" ["EndTime"]=> string(7) "10:00PM" ["Location"]=> string(13) "Quiet Room" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(3) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Oct 26 2016 12:00AM" }
[8]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "DE7A6045-2908-47B6-AD13-6DC12FF42F6E" ["offering"]=> string(15) "YOGA Session 2" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Sa" ["StartDate"]=> string(10) "11/12/2016" ["EndDate"]=> string(10) "11/12/2016" ["StartTime"]=> string(7) " 9:00AM" ["EndTime"]=> string(7) " 5:00PM" ["Location"]=> string(11) "YOGA Class" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(3) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Oct 26 2016 12:00AM" }
[9]=> array(20) { ["category"]=> string(7) "Classes" ["course"]=> string(5) "YOGA" ["CourseOfferingID"]=> string(36) "DE7A6045-2908-47B6-AD13-6DC12FF42F6E" ["offering"]=> string(15) "YOGA Session 2" ["Semester"]=> string(9) "Fall 2016" ["Days"]=> string(2) "Su" ["StartDate"]=> string(10) "11/13/2016" ["EndDate"]=> string(10) "11/13/2016" ["StartTime"]=> string(7) " 9:00AM" ["EndTime"]=> string(7) " 5:00PM" ["Location"]=> string(11) "YOGA Class" ["pricing"]=> NULL ["SIZE"]=> int(10) ["REGISTERED_COUNT"]=> int(3) ["WAITING_LIST_COUNT"]=> int(0) ["ProgramClassificationID"]=> string(36) "AFCAB0B2-24FE-427B-8590-812D74749E6A" ["ProgramClassificationName"]=> string(8) "Wellness" ["SemesterID"]=> string(36) "854E61F8-B564-48F6-AFCD-FAEE597AFF0C" ["CourseID"]=> string(36) "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B" ["RegCloseDate"]=> string(19) "Oct 26 2016 12:00AM" } }
If you really want to use this format of array then you can get this solution by following code but this should not be used as it is not optimal solution. you have to use proper data structure for this, though i have given the code to solve your problem temporary:
$yoga = [["category" => "Classes","course" => "Yoga","CourseOfferingId" => "0550AA8D-F437-4578-BD98-95C51D017E62","offering" => "YOGA Session 1","Semester" => "Fall 2016","Days" =>"We", "StartDate" => "10/05/2016", "EndDate" => "10/05/2016", "StartTime" => " 6:00PM", "EndTime" => "10:00PM","Location" => "Off-Site, Quiet Room","pricing" => NULL,"SIZE" =>10,"REGISTERED_COUNT" => 10,"WAITING_LIST_COUNT" => 0,"ProgramClassificationID" => "AFCAB0B2-24FE-427B-8590-812D74749E6A","ProgramClassificationName" =>"Wellnes","SemesterID" => "854E61F8-B564-48F6-AFCD-FAEE597AFF0C","CourseID" => "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B","RegCloseDate" => "Sep 29 2016 12:00AM"],
["category" => "Classes","course" => "Yoga","CourseOfferingId" => "0550AA8D-F437-4578-BD98-95C51D017E62","offering" => "YOGA Session 2","Semester" => "Fall 2016","Days" =>"We", "StartDate" => "10/05/2011", "EndDate" => "10/05/2016", "StartTime" => " 6:00PM", "EndTime" => "10:00PM","Location" => "Off-Site, Quiet Room","pricing" => NULL,"SIZE" =>10,"REGISTERED_COUNT" => 10,"WAITING_LIST_COUNT" => 0,"ProgramClassificationID" => "AFCAB0B2-24FE-427B-8590-812D74749E6A","ProgramClassificationName" =>"Wellnes","SemesterID" => "854E61F8-B564-48F6-AFCD-FAEE597AFF0C","CourseID" => "84A92D24-12C3-4487-93C1-4DBFAF2D9A3B","RegCloseDate" => "Sep 29 2016 12:00AM"]];
$sessions = [];
$sessionInformation = [];
foreach($yoga as $key => $yogaElements)
{
$temporarySessionInfo = [];
$sessionName = "";
foreach($yogaElements as $key => $value )
{
if($key == "offering"){
$sessionName = explode(" ",$value)[1]." ".explode(" ",$value)[2];
}
if($key == "StartDate"){
array_push($temporarySessionInfo,"Start Date: ".$value);
}
if($key == "EndDate"){
array_push($temporarySessionInfo,"End Date: ".$value);
}
if($key == "StartTime"){
array_push($temporarySessionInfo,"StartTime: ".$value);
}
if($key == "EndTime"){
array_push($temporarySessionInfo,"End Time: ".$value);
}
}
if(!array_key_exists($sessionName,$sessions))
{
$sessions[$sessionName] = $temporarySessionInfo;
}
else
{
$sessions[$sessionName] = array_merge($sessions[$sessionName], $temporarySessionInfo);
}
}
foreach($sessions as $key => $values)
{
echo $key."<br/>";
foreach($values as $value)
{
echo $value."<br/>";
}
echo "<br/>";
}
I ended up using this within my nested foreach...
if ($key=="YOGA")
{
for($i=0;$i<count($value);$i++)
{if(!array_key_exists($value[$i]["offering"], $class))
$class[$value[$i]["offering"]] = array();
array_push($class[$value[$i]["offering"]], $value[$i]);
}
foreach($class as $key => $rows):
//echo something
echo $key;
$k = 0;
foreach ($rows as $row) :
//echo something
$k++;
endforeach;
endforeach;
} else {
// show remaining non-YOGA classes
}
I need to output following array
object(stdClass)#6 (14) { ["subcategories"]=>
array(9) { [0]=> object(stdClass)#31 (13) { ["id"]=> string(2) "10"
["parent_id"]=> string(1) "6" ["name"]=> string(8) "Soup" ["description"]=> string(0) "" ["url"]=> string(4) "supy" ["meta_title"]=> string(8) "Soup" ["meta_keywords"]=> string(8) "Soup" ["meta_description"]=> string(0) "" ["image"]=> string(0) "" ["visible"]=> string(1) "1" ["position"]=> string(1) "7" ["path"]=> array(2) { [0]=> RECURSION [1]=> RECURSION } ["children"]=> array(1) { [0]=> int(10) } } [1]=> object(stdClass)#32 (13) { ["id"]=> string(2) "11" ["parent_id"]=> string(1) "6" ["name"]=> string(12) "Сашими" ["description"]=> string(0) "" ["url"]=> string(7) "sashimi" ["meta_title"]=> string(12) "Сашими" ["meta_keywords"]=> string(12) "Сашими" ["children"]=> array(1) { [0]=> int(10) } } [1]=> object(stdClass)#32 (13) { ["id"]=> string(2) "11" ["parent_id"]=> string(1) "6" ["name"]=> string(12) "Сашими" ["description"]=> string(0) "" ["url"]=> string(7) "sashimi" ["meta_title"]=> string(12) "Сашими" ["meta_keywords"]=> string(12) "Сашими" ["meta_description"]=> string(0) "" ["image"]=> string(0) "" ["visible"]=> string(1) "1" ["position"]=> string(1) "8" ["path"]=> array(2) { [0]=> RECURSION [1]=> RECURSION }
i think that here is multiple foreach need for output each ["name"] from ["subcategories"]
Now i've the following code
{foreach name=cats from=$category->name item=n}
<li>
<a href="catalog/{$n->url}" category_id="{$n->id}">
<b>{$n}</b>
</a>
</li>
{/foreach}
which displays only one Name of the current category (Soup).
How can i output each ["name"] from ["subcategories"] ?
As you said, you need a foreach for every level:
{foreach name=cats from=$category->name item=n}
<li>
<a href="catalog/{$n->url}" category_id="{$n->id}">
<b>{$n}</b>
</a>
{foreach name=subcats from=$n.subcategories item=s}
....
{/foreach}
</li>
{/foreach}
or maybe is from=$n->subcategories, I'm not sure, as you put all the array in a single line and it's difficult to see it