Forming final array with multiple array in PHP [duplicate] - php

This question already has answers here:
How to find array / dictionary value using key?
(2 answers)
Closed 3 years ago.
I need to form the final array, its not displaying how i am expecting, here is the code i used.
I need to print the final array in the expected format, I have attached the output how i am looking for in the below section,
<?php
$order_id = 12345;
$array1 = array(
"firstName" => "Test Fname",
"lastName" => "Test Lname",
"address1" => "Test Address",
"city" => "Test City",
"country" => "IND",
"email" => "test#blank.in"
);
$array2 = array(
"firstName" => "Test Fname",
"lastName" => "Test Lname",
"address1" => "Test Address",
"city" => "Test City",
"country" => "IND",
"email" => "test#blank.in"
);
$result = array("user_id" =>"9999","item_id" =>"cloth","price" =>"500","qty" =>"100");
$itemDetails = array();
foreach($result as $res){
$itemDetails[] =
array(
"User" => array(
"uservalue" => $res['user_id'],
"imageId" => $res['item_id']
),
"price" => $res['price'],
"qty" => $res['qty']
);
}
$final_array = array(
"id" => $order_id,
"billing" => $array1,
"shipping" => $array2,
"item" => $itemDetails
);
echo '<pre>';
print_r($final_array);die;
?>
Output of current Code
Array
(
[id] => 12345
[billing] => Array
(
[firstName] => Test Fname
[lastName] => Test Lname
[address1] => Test Address
[city] => Test City
[country] => IND
[email] => test#blank.in
)
[shipping] => Array
(
[firstName] => Test Fname
[lastName] => Test Lname
[address1] => Test Address
[city] => Test City
[country] => IND
[email] => test#blank.in
)
[item] => Array
(
[0] => Array
(
[User] => Array
(
[uservalue] => 9999
[imageId] => cloth
)
[price] => 500
[qty] => 100
)
[1] => Array
(
[User] => Array
(
[uservalue] => 9999
[imageId] => cloth
)
[price] => 500
[qty] => 100
)
[2] => Array
(
[User] => Array
(
[uservalue] => 9999
[imageId] => cloth
)
[price] => 500
[qty] => 100
)
)
)
Expected Result should be like below
array
(
"id" => 12345
"billing" => array
(
[firstName] => Test Fname,
[lastName] => Test Lname,
[address1] => Test Address,
[city] => Test City,
[country] => IND,
[email] => test#blank.in
)
"shipping" => array
(
[firstName] => Test Fname,
[lastName] => Test Lname,
[address1] => Test Address,
[city] => Test City,
[country] => IND,
[email] => test#blank.in
)
"item" => array
(
array
(
"User" => Array
(
"uservalue" => 9999,
"imageId" => cloth
)
[price] => 500,
[qty] => 100
)
)
)
I am expecting output like above, can we display the final array in that format, can anyone look into it and update me your thoughts. Thanks!!

if you allow only single item in itemdetails
$itemDetails[] =
[
"User" => [
"uservalue" => $result['user_id'],
"imageId" => $result['item_id'],
],
"price" => $result['price'],
"qty" => $result['qty'],
];
Single item demo
if itemdetails allow multiple items
$result = [
["user_id" =>"9999","item_id" =>"cloth","price" =>"500","qty" =>"100"],
["user_id" =>"9999","item_id" =>"cloth","price" =>"400","qty" =>"200"]
];
$itemDetails = array();
foreach($result as $res){
$itemDetails[] =
array(
"User" => array(
"uservalue" => $res['user_id'],
"imageId" => $res['item_id']
),
"price" => $res['price'],
"qty" => $res['qty']
);
}
Multiple items demo

If $result has multiple values, this should work.
$result = array(array("user_id" =>"9999","item_id" =>"cloth","price" =>"500","qty" =>"100"),array("user_id" =>"500","item_id" =>"cloth123","price" =>"511","qty" =>"80"));
$itemDetails = array();
foreach($result as $res){
$itemDetails[] =
array(
"User" => array(
"uservalue" => $res['user_id'],
"imageId" => $res['item_id']
),
"price" => $res['price'],
"qty" => $res['qty']
);
}
$final_array = array(
// "id" => $order_id,
// "billing" => $array1,
// "shipping" => $array2,
"item" => $itemDetails
);
echo '<pre>';
print_r($final_array);
Output
Array
(
[item] => Array
(
[0] => Array
(
[User] => Array
(
[uservalue] => 9999
[imageId] => cloth
)
[price] => 500
[qty] => 100
)
[1] => Array
(
[User] => Array
(
[uservalue] => 500
[imageId] => cloth123
)
[price] => 511
[qty] => 80
)
)
)

Related

Group values in multi-dimensional array based on a key

I have the following multi-dimensional array:
Array
(
[0] => Array
(
[sname] => florida
[cname] => orlando
)
[1] => Array
(
[sname] => texas
[cname] => dallas
)
[2] => Array
(
[sname] => florida
[cname] => tampa
)
[3] => Array
(
[sname] => ohio
[cname] => columbus
)
)
How would I go about trying to get all 'cname' values associated with each 'sname' value?
florida: orlando, tampa
texas: dallas
ohio: columbus
There are probably several ways to do this. The one that comes to mind is something like this:
<?php
$payload = [];
$origin = [
[
'sname' => 'florida',
'cname' => 'orlando'
],
[
'sname' => 'texas',
'cname' => 'dallas'
],
[
'sname' => 'florida',
'cname' => 'tampa'
],
[
'sname' => 'ohio',
'cname' => 'columbus'
]
];
foreach ($origin as $value) {
if (! isset($payload[$value['sname']])) {
$payload[$value['sname']] = '';
}
$payload[$value['sname']] .= (strlen($payload[$value['sname']]) >0?',':'') . $value['cname'];
}
print_r($payload);
Cheers! :)
=C=
With a slight tweak of Mike's solution (https://stackoverflow.com/a/2189916/4954574), the following will produce what I was hoping for:
$input_arr = array(
array("sname" => "florida", "cname" => "orlando"),
array("sname" => "texas", "cname" => "dallas"),
array("sname" => "florida", "cname" => "tampa"),
array("sname" => "ohio", "cname" => "columbus")
);
foreach ($input_arr as $key => &$entry) {
$level_arr[$entry['sname']][$key] = $entry['cname'];
}
print_r($level_arr);
Output:
Array
(
[florida] => Array
(
[0] => orlando
[2] => tampa
)
[texas] => Array
(
[1] => dallas
)
[ohio] => Array
(
[3] => columbus
)
)

Php check and replace if value exist in multi array?

Problem:
I dont know/understand how to check if date and place exists on the same "row" and they exists more then once.
Second, how do i then merge an array
my case MergeArray with ArraySchedule
Code:
$ArraySchedule = array();
while ($data = $stmt -> fetch(PDO::FETCH_ASSOC)) {
$schedules = array(
"id" => $data['id'],
"name" => $data['name'],
"date" => $data['date'],
"time" => $data['time'],
"place_id" => $data['place_id'],
"place" => $data['place'],
);
array_push($ArraySchedule, $schedules);
}
$dupe_array = array();
foreach ($ArraySchedule as $key => $value) {
if(++$dupe_array[$value["date"]] > 1 && ++$dupe_array[$value["place_id"]] > 1 ){
// this statement is wrong, i want something like:
// if date and place_id exists on the same "row" and they exists more then once
}
}
What i want to do:
Check if ArraySchedule contains schedules that have the same date and place,
if there is more than one schedule that has the same date and place_id.
then I want to update ArraySchedule with this structure
$MergeArray = array(
"id" => ArraySchedule['id'],
"name" => array(
"name" => scheduleSameDateAndPlace['name'],
"name" => scheduleSameDateAndPlace['name'],
"name" => scheduleSameDateAndPlace['name'],
),
"date" => $ArraySchedule['date'],
"time" => $ArraySchedule['time'],
"place_id" => $ArraySchedule['place_id'],
"place_name" => $ArraySchedule['place_name'],
),
MergeArray with ArraySchedule?
anyway...
Output I think I want?
Print_r($ArraySchedule)
array(
[0] =>
array(
[id] => 1
[names] => Simon
[date] => 2019-01-02
[time] 18.00
[place_id] => Tystberga Park
[place] => Tystberga
)
[1] =>
array(
[id] => 2
//[names] insted of [name]?
[names] =>
array(
[name] => Vincent
[name] => Angel
[name] => Kim
)
[date] => 2019-02-17
[time] => 13.00
[place_id] => Borås Park
[place] => Borås
)
[2] =>
array(
[id] => 3
// [names] is always an array?
[names] => Caitlyn
[date] => 2019-03-15
[time] 13.00
[place_id] => Plaza Park
[place] => EvPark
)
)
You can use array-reduce. Consider the following:
function mergeByDateAndPlace($carry, $item) {
$key = $item["place_id"] . $item["date"]; // creating key matching exact place and date
if (!isset($carry[$key])) {
$carry[$key]["name"] = $item["name"];
} else {
$carry[$key] = $item;
$item["name"] = [$item["name"]]; // make default array with 1 element so later can be append other names
}
return $carry;
}
Now use it with:
$MergeArray = array_reduce($ArraySchedule, "mergeByDateAndPlace", []);
If you later want to know if there were any duplicate you can just loop on $MergeArray. You can also use array_values if you want to discard the concat keys.
Notice #Nick 2 important comment about saving the first loop and the "time" value that need to be decided. Also notice your desire output contain multi element with the same key ("name") - you need to append them with int key - Array can not have duplicate keys.
Hope that helps!
Here is my data from my database:
var_export($ArraySchedule)
array (
0 => array ( 'id' => '225', 'place_id' => 'Alviks Kulturhus', 'name' => 'BarraBazz', 'date' => '2019-03-19', 'placeadress' => 'Gustavslundsvägen 1', ),
1 => array ( 'id' => '229', 'place_id' => 'Axelhuset Göteborg', 'name' => 'Anders Björk', 'date' => '2019-04-08', 'placeadress' => 'Axel Dahlströms torg 3', ),
2 => array ( 'id' => '230', 'place_id' => 'Axelhuset Göteborg', 'name' => 'Black Jack', 'date' => '2019-04-08', 'placeadress' => 'Axel Dahlströms torg 3', ),
3 => array ( 'id' => '227', 'place_id' => 'Arosdansen Syrianska Kulturcentret', 'name' => 'BarraBazz', 'date' => '2019-05-08', 'placeadress' => 'Narvavägen 90', ),
4 => array ( 'id' => '228', 'place_id' => 'Aspåsnäset', 'name' => 'Blender', 'date' => '2019-05-25', 'placeadress' => 'Aspåsnäset 167', ),
5 => array ( 'id' => '226', 'place_id' => 'Arenan Västervik Resort', 'name' => 'Blender', 'date' => '2019-06-29', 'placeadress' => 'Lysingsvägen', ),
6 => array ( 'id' => '222', 'place_id' => 'Alingsåsparken', 'name' => 'Bendéns', 'date' => '2019-07-16', 'placeadress' => 'Folkparksgatan 3A', ),
7 => array ( 'id' => '223', 'place_id' => 'Alingsåsparken', 'name' => 'Charlies', 'date' => '2019-07-16', 'placeadress' => 'Folkparksgatan 3A', ),
8 => array ( 'id' => '224', 'place_id' => 'Allhuset Södertälje', 'name' => 'Cedrix', 'date' => '2019-07-16', 'placeadress' => 'Barrtorpsvägen 1A', ), )
I want to update the "name" with an array of names everytime that place_id and date are the same.
This is the output I want:
Array (
[0] =>
Array ( [id] => 225 [place_id] => Alviks Kulturhus [name] => BarraBazz [date] => 2019-03-19 [placeadress] => Gustavslundsvägen 1 )
[1] =>
Array ( [id] => 229 [place_id] => Axelhuset Göteborg [name] => Array([0] => Anders Björk [1] => Black Jack ) [date] => 2019-04-08 [placeadress] => Axel Dahlströms torg 3 )
[3] =>
Array ( [id] => 227 [place_id] => Arosdansen Syrianska Kulturcentret [name] => BarraBazz [date] => 2019-05-08 [placeadress] => Narvavägen 90 )
[4] =>
Array ( [id] => 228 [place_id] => Aspåsnäset [name] => Blender [date] => 2019-05-25 [placeadress] => Aspåsnäset 167 )
[5] =>
Array ( [id] => 226 [place_id] => Arenan Västervik Resort [name] => Blender [date] => 2019-06-29 [placeadress] => Lysingsvägen )
[6] =>
Array ( [id] => 222 [place_id] => [Alingsåsparken] [name] => Array([0] => Bendéns [1] => Charlies) [date] => 2019-07-16 [placeadress] => Folkparksgatan 3A )
[8] =>
Array ( [id] => 224 [place_id] => Allhuset Södertälje [name] => Cedrix [date] => 2019-07-16 [placeadress] => Barrtorpsvägen 1A ) )
Here is my updated code
$sql = "SELECT `schedule`.`id`,`schedule`.`place_id`,`schedule`.`name`,`schedule`.`date`,`places`.`placeadress` FROM `schedule` INNER JOIN `places` ON `schedule`.`place_id`=`places`.`place_id` ORDER BY `date`";
$stmt = $db -> prepare($sql);
$stmt -> execute();
$ArraySchedule = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_export($ArraySchedule);
$DatePlace = array();
foreach ($ArraySchedule as $key => $Schedule){
$Arrayquery = "SELECT `schedule`.`id`,`schedule`.`place_id`,`schedule`.`name`,`schedule`.`date`,`places`.`placeadress` FROM `schedule` INNER JOIN `places` ON `schedule`.`place_id`=`places`.`place_id` WHERE `schedule`.`date`= :date_ AND `schedule`.`place_id` = :place_id ORDER BY `date`";
$ArrayStmt = $db->prepare($Arrayquery);
$ArrayStmt -> execute(array(":date_" => $Schedule['date'],":place_id" => $Schedule['place_id']));
//Getting every $Schedule that has the same date and place_id
if($ArrayStmt->rowCount() > 1){
//Here i want two update the name inside
//$ArrayArraySchedule with an array of names
//that has the same place and date?
}
}
print_r($ArraySchedule);

associative array check any column is empty or not

I have associative array like -
[0] => Array
(
[date] => 2018-06-22
[id] => 2282991
[type] => VIDEO
[domain] =>
[code] => Austin
[address] => Phone
)
[1] => Array
(
[date] => 2018-06-22
[id] => 2282991
[type] => VIDEO
[domain] =>
[code] =>
[address] => Phone
)
[3] => Array
(
[date] => 2018-06-22
[id] => 2282991
[type] => VIDEO
[domain] =>
[code] => Austin
[address] => Phone
)
I need to check is there any column having all the values are blank.
That means it should return only domain from above array because it is blank everywhere.
Is there any way to do this with minimum use of forloop? I need to check this for all these columns.
This will work if your subarray having same number of keys.Like "Date, id, Type etc".
$array = [
[ "date" => "2018-06-22", "id" => 2282991, "type" => "VIDEO", "domain" =>'', "code" => "Austin", "address" => "Phone"],
[ "date" => "2018-06-22", "id" => 2282991, "type" => "VIDEO", "domain" =>'', "code" => "", "address" => "Phone"],
[ "date" => "2018-06-22", "id" => 2282991, "type" => "VIDEO", "domain" =>'', "code" => "Austin", "address" => "Phone"]
];
$empty = [];
foreach($array[0] as $key=>$val){
$error = array_column($array, $key);
if(empty (array_filter($error)) ) {
$empty[] = $key;
}
}
print_r($empty);
Output:
Array
(
[0] => domain
)

Merging two multi-dimensional arrays using key and adding values

I want to merge two array's using key(product_id) and adding that values(usage).
Array 1
Array
(
[0] => Array
(
[name] => Reschedule A Service
[usage] => 1
[product_id] => 8
)
[1] => Array
(
[name] => Adding An Image
[usage] => 1
[product_id] => 5
)
[2] => Array
(
[name] => Each Calendar Event
[usage] => 1
[product_id] => 14
)
)
Array 2
Array
(
[0] => Array
(
[name] => Adding An Image
[usage] => 1
[product_id] => 5
)
[1] => Array
(
[name] => Schedule A Service
[usage] => 3
[product_id] => 11
)
[2] => Array
(
[name] => Each Calendar Event
[usage] => 2
[product_id] => 14
)
[3] => Array
(
[name] => Sales Performance Dashboard
[usage] => 2
[product_id] => 30
)
[4] => Array
(
[name] => Quote
[usage] => 1
[product_id] => 32
)
)
I need an out put like this merging and adding usage values.
Array
(
[0] => Array
(
[name] => Adding An Image
[usage] => 2
[product_id] => 5
)
[1] => Array
(
[name] => Schedule A Service
[usage] => 3
[product_id] => 11
)
[2] => Array
(
[name] => Each Calendar Event
[usage] => 3
[product_id] => 14
)
[3] => Array
(
[name] => Sales Performance Dashboard
[usage] => 2
[product_id] => 30
)
[4] => Array
(
[name] => Quote
[usage] => 1
[product_id] => 32
)
[5] => Array
(
[name] => Reschedule A Service
[usage] => 1
[product_id] => 8
)
)
This is my code for creating arrays
foreach($query->rows as $product){
$top_products[]=array(
'name'=>$product['name'],
'usage'=>$product['pusage'],
'product_id'=>$product['product_id']
);
}
foreach($query_2->rows as $product){
$top_point_products[]=array(
'name'=>$product['name'],
'usage'=>$product['p_usage'],
'product_id'=>$product['product_id']
);
}
$first =array(
array(
"name" => "Reschedule A Service",
"usage" => 1,
"product_id" => 8
),
array(
"name" => "Adding An Image",
"usage" => 1,
"product_id" => 5
),
array(
"name" => "Each Calendar Event",
"usage" => 1,
"product_id" => 14
)
);
$second =array(
array(
"name" => "Adding An Image",
"usage" => 1,
"product_id" => 5
),
array(
"name" => "Schedule A Service",
"usage" => 3,
"product_id" => 11
),
array(
"name" => "Each Calendar Event",
"usage" => 2,
"product_id" => 14
),
array(
"name" => "Sales Performance Dashboard",
"usage" => 2,
"product_id" => 30
),
array(
"name" => "Quote",
"usage" => 1,
"product_id" => 32
)
);
$result = array_unique(array_merge($first,$second), SORT_REGULAR);
Use array_unique & array_merge
Use the array_merge function, like this:
$C = array_merge($A, $B);
print_r($C);
Read manual Array merge
try this code
<?php
$array1=array
(
0 => array(
'name' => "Reschedule A Service",
'usage' => 1,
'product_id' => 8
),
1 => Array
(
'name' => "Adding An Image",
'usage' => 1,
'product_id' => 5
),
2 => Array
(
'name' => "Each Calendar Event",
'usage' => 2,
'product_id' => 14
)
);
$array2=array
(
0 => Array
(
'name' => "Adding An Image",
'usage' => 1,
'product_id' => 5
),
1 => Array
(
'name' => "Schedule A Service",
'usage' => 3,
'product_id' => 11
),
2 => Array
(
'name' => "Each Calendar Event",
'usage' => 5,
'product_id' => 14
),
3 => Array
(
'name' => "Sales Performance Dashboard",
'usage' => 2,
'product_id' => 30
),
4 => Array
(
'name' => "Quote",
'usage' => 1,
'product_id' => 32
)
);
$product_id1=array_column($array1, 'product_id');
$product_id2=array_column($array2, 'product_id');
$new=array_intersect($product_id1,$product_id2);
foreach ($new as $key => $value) {
if(in_array($new[$key],$product_id2)){
$array2[array_search($new[$key],$product_id2)]['usage']+=$array1[$key]['usage'];
}
}
$new1=array_diff($product_id1,$product_id2);
foreach ($new1 as $key => $value) {
$array2[]=$array1[$key];
}
foreach ($array2 as $key => $value) {
echo "[".$key."]=><br>";
foreach ($value as $key1 => $value1) {
echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
echo "[".$key1."]=>".$value1."<br>";
}
echo "<br>";
}
?>
output
[0]=>
[name]=>Adding An Image
[usage]=>2
[product_id]=>5
[1]=>
[name]=>Schedule A Service
[usage]=>3
[product_id]=>11
[2]=>
[name]=>Each Calendar Event
[usage]=>7
[product_id]=>14
[3]=>
[name]=>Sales Performance Dashboard
[usage]=>2
[product_id]=>30
[4]=>
[name]=>Quote
[usage]=>1
[product_id]=>32
[5]=>
[name]=>Reschedule A Service
[usage]=>1
[product_id]=>8
Use array_merge and a simple foreach loop to check your condition and update the usagevalues.
See below
$result = array_merge($arrArray1, $arrArray2);
$result2 = array();
foreach($result as $key => $value){
if(array_key_exists($value['product_id'], $result2)){
$result2[$value['product_id']]['usage'] += $value['usage'];
} else{
$result2[$value['product_id']] = $value;
}
}
print_r($result2);
If you want to reset your resultant array indexes use array_merge again like this
$result2 = array_merge($result2);
Hope this will help

Print an html table from php array

I need to print out a table, starting from a PHP array, adding some columns for further utilization.
The array is this:
Array ( [0] => Array ( [tid] => 1 [token] => andrea [participant_info] => Array ( [firstname] => Andrea [lastname] => AndreaLastName [email] => andrea#email.com ) ) [1] => Array ( [tid] => 3 [token] => 1 [participant_info] => Array ( [firstname] => 1FirstName [lastname] => 1LastName [email] => 1#email.com ) ) [2] => Array ( [tid] => 4 [token] => 2 [participant_info] => Array ( [firstname] => 2FirstName [lastname] => 2LastName [email] => 2#email.com ) ) [3] => Array ( [tid] => 5 [token] => 3 [participant_info] => Array ( [firstname] => 3FirstName [lastname] => 3LastName [email] => 3#email.com ) ) [4] => Array ( [tid] => 6 [token] => 4 [participant_info] => Array ( [firstname] => 4FirstName [lastname] => 4LastName [email] => 4#email.com ) ) [5] => Array ( [tid] => 7 [token] => 5 [participant_info] => Array ( [firstname] => 5FirstName [lastname] => 5LastName [email] => 5#email.com ) ) [6] => Array ( [tid] => 8 [token] => 6 [participant_info] => Array ( [firstname] => 6FirstName [lastname] => 6LastName [email] => 6#email.com ) ) [7] => Array ( [tid] => 9 [token] => 7 [participant_info] => Array ( [firstname] => 7FirstName [lastname] => 7LastName [email] => 7#email.com ) ) [8] => Array ( [tid] => 10 [token] => test [participant_info] => Array ( [firstname] => testFirstName [lastname] => testLastName [email] => test#email.com ) ) [9] => Array ( [tid] => 11 [token] => test3 [participant_info] => Array ( [firstname] => firstnameTest [lastname] => lastnameTest [email] => test2#email.com ) ) )
And it's look like that using some online tool:
What I need is to create an HTML table ( using classic < table> or < div> doesn't care )
That looks like this:
Where the token is not directly printed but it's available as $variable to use for some script ( I need to add icon to download a file called "$token.pdf" )
Thanks for any suggestion.
I found some function that prints the array directly as it appear but I do not know how to adapt to my needs:
function build_table($array){
// start table
$html = '<table border="1" style="width:100%">';
// header row
$html .= '<tr>';
foreach($array[0] as $key=>$value){
$html .= '<th>' . $key . '</th>';
}
$html .= '</tr>';
// data rows
foreach( $array as $key=>$value){
$html .= '<tr>';
foreach($value as $key2=>$value2){
$html .= '<td>' . $value2 . '</td>';
}
$html .= '</tr>';
}
// finish table and return it
$html .= '</table>';
return $html;
}
I remade the array to give a good example.
As you see i use 2 foreach loops.
The first one is to loop trough the main array '$array'.
The second foreach, in the first foreach, loops trough the array from 'participant_info'.
The $i stands for the value from the array.
So if you type: $i['did'], it loops trough all the values from 'tid'.
I hope this explains it.
Good luck!
<?php
// Made array
$array[0] = array("tid" => 1, "token" => "andrea", "participant_info" => array("firstname" => "Andrea", "lastname" => "AndreaLastName", "email" => "andrea#email.com" ));
$array[1] = array("tid" => 3, "token" => 1, "participant_info" => array("firstname" => "1FirstName", "lastname" => "1LastName", "email" => "1#email.com" ));
$array[2] = array("tid" => 4, "token" => 2, "participant_info" => array("firstname" => "2FirstName", "lastname" => "2LastName", "email" => "2#email.com" ));
$array[3] = array("tid" => 5, "token" => 3, "participant_info" => array("firstname" => "3FirstName", "lastname" => "3LastName", "email" => "3#email.com" ));
$array[4] = array("tid" => 6, "token" => 4, "participant_info" => array("firstname" => "4FirstName", "lastname" => "4LastName", "email" => "4#email.com" ));
$array[5] = array("tid" => 7, "token" => 5, "participant_info" => array("firstname" => "5FirstName", "lastname" => "5LastName", "email" => "5#email.com" ));
$array[6] = array("tid" => 8, "token" => 6, "participant_info" => array("firstname" => "6FirstName", "lastname" => "6LastName", "email" => "6#email.com" ));
$array[7] = array("tid" => 9, "token" => 7, "participant_info" => array("firstname" => "7FirstName", "lastname" => "7LastName", "email" => "7#email.com" ));
$array[8] = array("tid" => 10, "token" => "test", "participant_info" => array("firstname" => "testFirstName", "lastname" => "testLastName", "email" => "test#email.com" ));
$array[9] = array("tid" => 11, "token" => "test3", "participant_info" => array("firstname" => "firstnameTest", "lastname" => "lastnameTest", "email" => "test2#email.com" ));
?>
<table>
<tr>
<th>tid</th>
<th>token</th>
<th>participant_info</th>
<th>firstname</th>
<th>lastname</th>
<th>email</th>
</tr>
<? foreach($array as $h => $i): ?>
<tr>
<td><?=$i['tid']?></td>
<td><?=$i['token']?></td>
<? foreach($i['participant_info'] as $p): ?>
<td><?=$p?></td>
<? endforeach; ?>
</tr>
<? endforeach; ?>
</table>

Categories