Skip to content

Instantly share code, notes, and snippets.

@prodhan
Created June 7, 2021 06:50
Show Gist options
  • Save prodhan/fa55931c27c0d49ef853a4f6d6e6a038 to your computer and use it in GitHub Desktop.
Save prodhan/fa55931c27c0d49ef853a4f6d6e6a038 to your computer and use it in GitHub Desktop.
<?php
/* Q1: Suppose this array come from back-end. data of this array can be dynamic.
You have to make a Dynamic HTML Output (using ul tag) based on this array,
where each item will fall under its parent id.
output will look something like this.
Bangladesh
Dhaka
Uttara
Khilgaon
Noyakhali
Maijdi
Canada
Torrento
*/
$arr = [
[
"id" => 500,
"p_id" => 0,
"title" => "Bangladesh"
],
[
"id" => 510,
"p_id" => 500,
"title" => "Dhaka"
],
[
"id" => 511,
"p_id" => 510,
"title" => "Uttara"
],
[
"id" => 512,
"p_id" => 510,
"title" => "Khailgaon"
],
[
"id" => 513,
"p_id" => 500,
"title" => "NoyaKhali"
],
[
"id" => 514,
"p_id" => 513,
"title" => "Maijdi"
],
[
"id" => 515,
"p_id" => 0,
"title" => "Canada"
],
[
"id" => 516,
"p_id" => 515,
"title" => "Toronto"
],
];
@Amir2417
Copy link

code
output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment