First i had this:
$myArray = getDatabaseData($p1);
header('Content-Type: application/json');
echo json_encode($myArray );
This was working well, the echo of json data was working correctly.
But now i wanted to add another array data receives data from other query. Like this:
$myArray = getDatabaseData($p1); //returns 2 dimensions array
$myArray2 = getDatabaseData2($p2); //returns 2 dimensions array
$finalArray = array();
$finalArray['data1'] = $myArray;
$finalArray['data2'] = $myArray2;
header('Content-Type: application/json');
echo json_encode($finalArray);
And is not doing the echo.
I've discovered that if i do echo json_encode($myArray); it does the echo.
But if i do echo json_encode($myArray2); it does not.
Note: getDatabaseData function does only one query to the DB. getDatabaseData2 does 4, that are then combined in a single array.
Is it because i am combining multiple db queries in my getDatabaseData2 function?
Here is the print_r of $myArray and $myArray2 :
myArray:
Array
(
[values] => Array
(
[0] => 0
[1] => 2
[2] => 3
[3] => 2
[4] => 7
[5] => 17
[6] => 6
[7] => 5
[8] => 9
[9] => 0
)
[keys] => Array
(
[0] => G. M.
[1] => G. S.
[2] => Cruz.
[3] => At.
[4] => Rem. C.
[5] => Rem. S.
[6] => Fs.
[7] => Rec.
[8] => B. P.
[9] => V. F.
)
)
myArray2:
Array
(
[names] => Array
(
[77] => André
[78] => Daniel
[79] => Rúben
[80] => Ant�nio
[81] => João
[83] => João
)
[nums] => Array
(
[77] => 0
[78] => 2
[79] => 0
[80] => 0
[81] => 0
[83] => 6
)
[nums2] => Array
(
[77] => 0
[78] => 0
[79] => 4
[80] => 0
[81] => 3
[83] => 0
)
)
Thanks for the help.
Here I tried but its working!
<!DOCTYPE html>
<html>
<head>
<title>My Title</title>
</head>
<body>
<?php
$arr = array(array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5),array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5));
$arr2 = array(array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5),array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5),array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5));
$finalArray = [];
$finalArray[] = $arr;
$finalArray[] = $arr2;
echo json_encode($finalArray); die();
?>
</body>
</html>
Related
I am making API request to Google Sheets and I receive this response:
Array
(
[0] => Array
(
[Title] => Hours
[January] => 1
[February] => 2
[March] => 3
[April] => 4
[May] => 5
[June] => 6
[July] => 7
[August] => 8
)
[1] => Array
(
[Title] => Days
[January] => 3
[February] => 5
[March] => 1
[April] => 6
[May] => 3
[June] => 7
[July] => 4
[August] => 2
)
[2] => Array
(
[Title] => Weeks
[January] => 3
[February] => 5
[March] => 3
[April] => 4
[May] => 0
[June] => 0
[July] => 2
[August] => 6
[September] => 0
[October] => 0
[November] => 1
[December] => 0
)
)
How could I loop trough and modify this array to something like this so I can use it with HighCharts JS library?
series: [{
title: 'Hours',
data: [1, 2, 3, 4, 5, 6 .......]
}, {
title: 'Days',
data: [4, 6, 3, 6, ........]
}, {
title: 'Weeks',
data: [1, 9, 1, 3, ........]
}, {
....
}]
I tried this way:
if ($response->status) {
$rawData = json_decode(json_encode($response->data), true);
}
$series = [];
foreach ($rawData as $index => $rawDatum) {
if (!isset($rawDatum['Title'])) {
continue;
}
foreach ($rawDatum as $columnKey => $value) {
if ($columnKey == 'CvA') {
$series[$columnKey]['Title'][] = $value;
}
}
}
What I got as result:
Array
(
[Title] => Array
(
[title] => Array
(
[0] => Hours
[1] => Days
[2] => Weeks
)
)
)
Also is there a way to get all names of the months saved in $months array for example without doubles?
The following piece of code will create an array with title and the values for each respective subarray Hours, Days, Weeks.
We will also collect the union of the months in an array named $months.
$series = [];
$months = [];
foreach ($rawData as $subarray) {
$title = $subarray['Title'];
// Remove title key
unset($subarray['Title']);
$series[] = [
'title' => $title,
'data' => array_values($subarray),
];
// Union operator to keep unique months.
$months += array_keys($subarray);
}
echo '<pre>';
print_r($months);
echo '</pre>';
echo '<pre>';
print_r($result);
echo '</pre>';
Result $months:
Array
(
[0] => January
[1] => February
[2] => March
[3] => April
[4] => May
[5] => June
[6] => July
[7] => August
[8] => September
[9] => October
[10] => November
[11] => December
)
Result $series:
Array
(
[0] => Array
(
[title] => Hours
[data] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
)
)
[1] => Array
(
[title] => Days
[data] => Array
(
[0] => 3
[1] => 5
[2] => 1
[3] => 6
[4] => 3
[5] => 7
[6] => 4
[7] => 2
)
)
[2] => Array
(
[title] => Weeks
[data] => Array
(
[0] => 3
[1] => 5
[2] => 3
[3] => 4
[4] => 0
[5] => 0
[6] => 2
[7] => 6
[8] => 0
[9] => 0
[10] => 1
[11] => 0
)
)
)
Given this data:
$data = [
[
'Title' => 'Hours',
'January' => 1,
'February' => 2,
'March' => 3,
'April' => 4,
'May' => 5,
'June' => 6,
'July' => 7,
'August' => 8,
],
[
'Title' => 'Days',
'January' => 3,
'February' => 5,
'March' => 1,
'April' => 6,
'May' => 3,
'June' => 7,
'July' => 4,
'August' => 2,
],
[
'Title' => 'Weeks',
'January' => 3,
'February' => 5,
'March' => 3,
'April' => 4,
'May' => 0,
'June' => 0,
'July' => 2,
'August' => 6,
'September' => 0,
'October' => 0,
'November' => 1,
'December' => 0,
]
];
You should be able to do this:
// Store everything here
$result = [];
foreach ($data as $item) {
// Grab the title
$ret['title'] = $item['Title'];
// Remove it from the source dataset
unset($item['Title']);
// Take the remaining values, join with comma
$ret['data'] = implode(',', array_values($item));
// Append to main array
$result[] = $ret;
}
You can skip the implode if want an actual array
I would like to combine 2 arrays into 1 in PHP or laravel. I've searched this site for similar questions but can't seem to find an answer.
Can someone help me with this?
**array 1 -- $insertData **
Array
(
[0] => Array
(
[prid] => 4
[vendor_id] => 1
)
[1] => Array
(
[prid] => 5
[vendor_id] => 2
)
)
**Array - 2 $requestData **
Array
(
[vendor_id] => Array
(
[0] => 1
[1] => 1
[2] => 2
[3] => 2
)
[item] => Array
(
[0] => 2
[1] => 3
[2] => 4
[3] => 5
)
[qty] => Array
(
[0] => 12
[1] => 13
[2] => 14
[3] => 15
)
)
**Required Output ---- how can I do this array1 and array2 combine into a single array **
Array
(
[0] => Array
(
[prid] => 4
[vendor_id] => 1
[item] => 2
[qty] => 12
)
[1] => Array
(
[prid] => 4
[vendor_id] => 1
[item] => 3
[qty] => 13
)
[2] => Array
(
[prid] => 5
[vendor_id] => 2
[item] => 4
[qty] => 14
)
[3] => Array
(
[prid] => 5
[vendor_id] => 2
[item] => 5
[qty] => 15
)
)
My controller
public function prtmulti(Request $req)
{
$maxPrId = newpr::max('prid');
// print_r($maxPrId);
echo "<pre>";
$requestData = $req->all();
if (array_key_exists("vendor_name", $requestData)) {
$insertData = [];
$uniqueData = array_unique($requestData["vendor_name"]);
foreach ($uniqueData as $key => $value) {
$maxId = $maxPrId+1;
$insertData[] = ['prid' => $maxId, 'vendor_id' => $value];
$maxPrId = $maxPrId+1;
}
}
print_r($insertData);
print_r($requestData);
}
you can achieve this using the array_combine function in php, for example:
<?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");
$c=array_combine($fname,$age);
print_r($c);
?>
I'm pretty sure that Laravel doesn't offer anything out of the box to execute your desired merging technique (and I don't see why it would bother).
Assuming that the vendor_id values in the first array are unique, you will get best performance by creating a lookup array. array_column() can be used to declare an array with vendor_id values as keys and prid values as values.
Because your $requestData has rows with the number of columns desired in the output, loop over the $requestData['vendor_id'] data and manually generate the desired rows of data in the result array.
Code: (Demo)
$insertData = [
['prid' => 4, 'vendor_id' => 1],
['prid' => 5, 'vendor_id' => 2],
];
$requestData = [
'vendor_id' => [1, 1, 2, 2],
'item' => [2, 3, 4, 5],
'qty' => [12, 13, 14, 15]
];
$insertLookup = array_column($insertData, 'prid', 'vendor_id');
$result = [];
foreach ($requestData['vendor_id'] as $index => $vendorId) {
$result[] = [
'prid' => $insertLookup[$vendorId],
'vendor_id' => $vendorId,
'item' => $requestData['item'][$index],
'qty' => $requestData['qty'][$index],
];
}
var_export($result);
Output:
array (
0 =>
array (
'prid' => 4,
'vendor_id' => 1,
'item' => 2,
'qty' => 12,
),
1 =>
array (
'prid' => 4,
'vendor_id' => 1,
'item' => 3,
'qty' => 13,
),
2 =>
array (
'prid' => 5,
'vendor_id' => 2,
'item' => 4,
'qty' => 14,
),
3 =>
array (
'prid' => 5,
'vendor_id' => 2,
'item' => 5,
'qty' => 15,
),
)
You can use the array_merge() function to merge arrays.
array_merge
$merged_array = array_merge($insertData, $requestData);
The following is my result array
Array (
[0] => Array
(
[ProductID] => 220
[TextID] => 477
[ProductName] => Hugo Woman
[Price] => 43.91
[BTW] => 21
[Stock] => 500
[BrandID] => 186
[ProductImage] => https://media.douglas-shop.com/874229/300_0/Hugo_Boss-Hugo_Woman-EdP_30ml_GRATIS_Nail_Polish_4ml.jpg
[CategoryID] => 1
[SubCategoryID] => 1
[View] => 0
)
[1] => Array
(
[ProductID] => 616
[TextID] => 959
[ProductName] => Hugo XY
[Price] => 44.95
[BTW] => 21
[Stock] => 500
[BrandID] => 186
[ProductImage] => https://media.douglas-shop.com/333660/300_0/Hugo_Boss-Hugo_XY.jpg
[CategoryID] => 2
[SubCategoryID] => 2
[View] => 0
)
[2] => Array
(
[ProductID] => 650
[TextID] => 991
[ProductName] => Hugo Just Different
[Price] => 45.76
[BTW] => 21
[Stock] => 500
[BrandID] => 186
[ProductImage] => https://media.douglas-shop.com/617162/300_0/Hugo_Boss-Hugo_Just_Different.jpg
[CategoryID] => 2
[SubCategoryID] => 2
[View] => 0
)
)
I have a second array with subcategories, in which the key is referencing to the SubCategoryID:
Array
(
[1] => Array
(
[EN] => Ladies
[NL] => Dames
)
[2] => Array
(
[EN] => Men
[NL] => Heren
)
)
I want to loop through the result array and remove the keys who don't have a SubCategoryID listed in the second array. I looked at http://php.net/manual/en/function.array-filter.php, but can't figure out the best way to do this.
Thank you!
There are two solutions to the above problem, one with using simple for loop and one with using array_walk() function.
Here, $result_array is your result array and $subcategory_array is your subcategory array.
Solution(1):
$subcategory_ids = array_keys($subcategory_array);
$arrLength = count($result_array);
for($i = 0; $i < $arrLength; ++$i){
if(!in_array($result_array[$i]['SubCategoryID'], $subcategory_ids)){
unset($result_array[$i]);
}
}
// display $result_array
echo "<pre>"; print_r($result_array);
Solution(2):
$subcategory_ids = array_keys($subcategory_array);
function filter_arr($item, $key){
global $result_array, $subcategory_ids;
if(!in_array($item['SubCategoryID'], $subcategory_ids)){
unset($result_array[$key]);
}
}
array_walk($result_array, "filter_arr");
// display $result_array
echo "<pre>"; print_r($result_array);
Please try i thnik this help to you..
$array = array (
0 => array
(
'ProductID' => 220,
'TextID' => 477,
'ProductName' => 'Hugo Woman',
'Price' => 43.91,
'BTW' => 21,
'Stock' => 500,
'BrandID' => 186,
'ProductImage' => 'https://media.douglas-shop.com/874229/300_0/Hugo_Boss-Hugo_Woman-EdP_30ml_GRATIS_Nail_Polish_4ml.jpg',
'CategoryID' => 1,
'SubCategoryID' => 1,
'View' => 0
),
1 => array
(
'ProductID' => 616,
'TextID' => 959,
'ProductName' => 'Hugo XY',
'Price' => 44.95,
'BTW' => 21,
'Stock' => 500,
'BrandID' => 186,
'ProductImage' => 'https://media.douglas-shop.com/333660/300_0/Hugo_Boss-Hugo_XY.jpg',
'CategoryID' => 1,
'SubCategoryID' => 2,
'View' => 0
),
'2' => array
(
'ProductID' => 650,
'TextID' => 991,
'ProductName' => 'Hugo Just Different',
'Price' => 45.76,
'BTW' => 21,
'Stock' => 500,
'BrandID' => 186,
'ProductImage' => 'https://media.douglas-shop.com/617162/300_0/Hugo_Boss-Hugo_Just_Different.jpg',
'CategoryID' => 2,
'SubCategoryID' => 1,
'View' => 0
),);
$array1 = array (
1 => array
(
'EN' => 'Ladies',
'NL' => 'Dames'
),
2 => array
(
'EN' => 'Men',
'NL' => 'Heren'
),);
foreach($array as $newArray){
if (array_key_exists($newArray['SubCategoryID'], $array1)) {
echo '<pre>';
print_r($newArray);
echo '</pre>';}}
here's my array
Array
(
[0] => Array
(
[0] => Jan 2010
[1] => 65.75
)
[1] => Array
(
[0] => Jan 2010
[1] => 211.05
)
[2] => Array
(
[0] => Jan 2010
[1] => 582.7
)
[3] => Array
(
[0] => Feb 2010
[1] => 136.3
)
[4] => Array
(
[0] => Feb 2010
[1] => 215.32
)
[5] => Array
(
[0] => Feb 2010
[1] => 413.9
)
[6] => Array
(
[0] => Mar 2010
[1] => 156.35
)
[7] => Array
(
[0] => Mar 2010
[1] => 210.54
)
[8] => Array
(
[0] => Mar 2010
[1] => 585.15
)
[9] => Array
(
[0] => Apr 2010
[1] => 126.1
)
[10] => Array
(
[0] => Apr 2010
[1] => 255.47
)
[11] => Array
(
[0] => Apr 2010
[1] => 329.1
)
[12] => Array
(
[0] => May 2010
[1] => 109
)
[13] => Array
(
[0] => May 2010
[1] => 170
)
[14] => Array
(
[0] => May 2010
[1] => 716.7
)
)
is there any way I can make all arrays with the same value in [0] merge? i want it to be something like this:
Array[0] = (Jan 2010, 65.75, 211.05, 582.7)
Array[1] = (Feb 2010, 136.3, 215.32, 413.9)
and so on...
The closest I can think to do this "simply" (read: taking advantage of native PHP features) is switching to text keys (associative array) for your result. This makes sense from a data modeling perspective as well, since in your sample result arrays you are mixing "key" data and "value" data (e.g. the first value carries the responsibility of being the label for the set == bad). The trick is to use the implicit "push" operator [], which appends a new value to an array.
foreach($sourceArray as $currentSubArray) {
$resultArray[$currentSubArray[0]][] = $currentSubArray[1];
}
Your result will look like this:
Array (
'Jan 2010' => Array (
0 => 65.75,
1 => 211.05,
2 => 582.7,
)
...
)
This is a variant of what #ctrahey suggested, that operates on the input array directly:
foreach($array as $key => &$entry) {
list($month, $value) = $entry;
if (isset($ptr[$month])) {
$ptr[$month][] = $value;
unset($array[$key]);
} else {
$ptr[$month] = &$entry;
}
}
unset($ptr);
Output with your example data:
Array
(
[0] => Array
(
[0] => Jan 2010
[1] => 65.75
[2] => 211.05
[3] => 582.7
)
[3] => Array
(
[0] => Feb 2010
[1] => 136.3
[2] => 215.32
[3] => 413.9
)
[6] => Array
(
[0] => Mar 2010
[1] => 156.35
[2] => 210.54
[3] => 585.15
)
[9] => Array
(
[0] => Apr 2010
[1] => 126.1
[2] => 255.47
[3] => 329.1
)
[12] => Array
(
[0] => May 2010
[1] => 109
[2] => 170
[3] => 716.7
)
)
actionMerge($inputArray);
function actionMerge($inputArray){
$month = array();
$earn = array();
$parentKey = 0;
$callback = function ($value, $key) use (&$month, &$earn, &$parentKey) {
if(!is_array($value)){
if($key == 0){
if(!in_array($value, $month)){
array_push($month, $value);
$earn[$value] = array();
}
$parentKey = $value;
}elseif($key == 1){
array_push($earn[$parentKey], $value);
}
}
};
array_walk_recursive($inputArray, $callback);
echo 'You should use this array';
var_dump($earn); // group money by month, I recommend you to use it
$Array = array();
foreach($month as $m){
$arr = array($m);
$arr = array_merge($arr, $earn[$m]);
array_push($Array, $arr);
}
echo '...Intead of array result what you expect';
var_dump($Array); // your expect result
}
?>
Here is result:
//You should use this array
array (size=5)
'Jan 2010' =>
array (size=3)
0 => float 65.75
1 => float 211.05
2 => float 582.7
'Feb 2010' =>
array (size=3)
0 => float 136.3
1 => float 215.32
2 => float 413.9
'Mar 2010' =>
array (size=3)
0 => float 156.35
1 => float 210.54
2 => float 585.15
'Apr 2010' =>
array (size=3)
0 => float 126.1
1 => float 255.47
2 => float 329.1
'May 2010' =>
array (size=3)
0 => int 109
1 => int 170
2 => float 716.7
//...Intead of array result what you expect
array (size=5)
0 =>
array (size=4)
0 => string 'Jan 2010' (length=8)
1 => float 65.75
2 => float 211.05
3 => float 582.7
1 =>
array (size=4)
0 => string 'Feb 2010' (length=8)
1 => float 136.3
2 => float 215.32
3 => float 413.9
2 =>
array (size=4)
0 => string 'Mar 2010' (length=8)
1 => float 156.35
2 => float 210.54
3 => float 585.15
3 =>
array (size=4)
0 => string 'Apr 2010' (length=8)
1 => float 126.1
2 => float 255.47
3 => float 329.1
4 =>
array (size=4)
0 => string 'May 2010' (length=8)
1 => int 109
2 => int 170
3 => float 716.7
It's quite horrible,but it works...
$resarray=Array(
0 => Array(0 => 'Jan 2010',1 => 65.75),
1=> Array(0 => 'Jan 2010',1 => 211.05),
2 => Array(0 => 'Jan 2010',1 => 582.7),
3 => Array(0 => 'Feb 2010',1 => 136.3),
4 => Array(0 => 'Feb 2010',1 => 215.32),
5 => Array(0 => 'Feb 2010',1 => 413.9),
6 => Array(0 => 'Feb 2010',1 => 156.35),
7 => Array(0 => 'Feb 2010',1 => 210.54),
8 => Array(0 => 'Mar 2010',1 => 585.15),
9 => Array(0 => 'Apr 2010',1 => 126.1),
10 => Array(0 => 'Apr 2010',1 => 255.47),
11 => Array(0 => 'Apr 2010',1 => 329.1),
12 => Array(0 => 'May 2010',1 => 109),
13 => Array(0 => 'May 2010',1 => 170),
14 => Array(0 => 'May 2010',1 => 716.7)
);
$CatArray=array();
$FinArray=array();
$count=count($resarray);
for($i=0;$i<$count;$i++){
$index=array_search($resarray[$i][0],$CatArray);
if(is_numeric($index) && $index>=0)
$FinArray[$index][]=$resarray[$i][1];
else{
$CatArray[]=$resarray[$i][0];
$FinArray[]=array($resarray[$i][0],$resarray[$i][1]);
}
}
unset($CatArray);
unset($resarray);
$count=count($FinArray);
for($i=0;$i<$count;$i++){
$resarray[$i]=implode(',',$FinArray[$i]);
}
Output:
Array
(
[0] => Jan 2010,65.75,211.05,582.7
[1] => Feb 2010,136.3,215.32,413.9,156.35,210.54
[2] => Mar 2010,585.15
[3] => Apr 2010,126.1,255.47,329.1
[4] => May 2010,109,170,716.7
)
It feels I am going way over my head while discovering the ultimate usage of arrays.
I have two arrays, where the first has main keys, and the value is a count of files attached to that key.
The goal is to match the keys of this first array to the values in a second array, but still mainting (and show) the (value)count of Array-1 -- but for only the values in the second array.
Seems somewhat hazy perhaps, but here are the arrays. The second one has the values that should match the keys in the first.
(My problem is that I keep losing the values of array 1 with every attempt I make.)
Hope you can help me out with this one.
(working matches are keys like: 125, 2051 & 2214)
Array 1:
Array (
[6960] => 3
[2214] => 4
[2051] => 4
[6944] => 2
[6938] => 4
[1823] => 1
[766] => 6
[3993] => 4
[5896] => 6
[6927] => 2
[4220] => 3
[77] => 3
[83] => 1
[125] => 2
[6618] => 2
[196] => 1
[4072] => 12
[3718] => 1
[5918] => 1
[3388] => 10
[4500] => 13
[5968] => 2
[3000] => 2
[942] => 1
[4246] => 8
[5868] => 2
[6394] => 3
[1168] => 1
[2163] => 1
[1827] => 2
[2071] => 8
[4597] => 1
[1702] => 7
)
Array 2:
Array (
[0] => 1024
[1] => 1076
[2] => 111
[3] => 124
[4] => 125
[5] => 1301
[6] => 1409
[7] => 2051
[8] => 2214
[9] => 2636
[10] => 3246
[11] => 4838
[12] => 6946
[13] => 6955
[14] => 6961
[15] => 73
[16] => 74
[17] => 8
)
What about doing this:
<?php
$arr1 = array(1 => 1000, 500 => 1111, 1000 => 5000, 5000 => 5555);
$arr2 = array(1, 5000);
print_r(array_intersect_key($arr1, array_flip($arr2)));
OUTPUT:
(
[1] => 1000
[5000] => 5555
)
Or, using your data:
<?php
$arr1 = array(6960 => 3, 2214 => 4, 2051 => 4, 6944 => 2, 6938 => 4, 1823 => 1, 766 => 6, 3993 => 4, 5896 => 6, 6927 => 2, 4220 => 3, 77 => 3, 83 => 1, 125 => 2, 6618 => 2, 196 => 1, 4072 => 12, 3718 => 1, 5918 => 1, 3388 => 10, 4500 => 13, 5968 => 2, 3000 => 2, 942 => 1, 4246 => 8, 5868 => 2, 6394 => 3, 1168 => 1, 2163 => 1, 1827 => 2, 2071 => 8, 4597 => 1, 1702 => 7);
$arr2 = array(1024, 1076, 111, 124, 125, 1301, 1409, 2051, 2214, 2636, 3246, 4838, 6946, 6955, 6961, 73, 74, 8);
print_r(array_intersect_key($arr1, array_flip($arr2)));
OUTPUT:
Array
(
[2214] => 4
[2051] => 4
[125] => 2
)
array_interset_keys will find the intersection of arrays by keys, not values. Since your second array is an index based array (not an associative array) we need to first flip the keys and values using array_flip. Then the keys can be intersected.
Your question is somewhat unclear, but I think this is what you're looking for:
foreach( $array2 as $key)
{
$count = ( isset( $array1[ $key ]) ? $array1[ $key ] : 0);
echo $key . ' has ' . $count . ' files.';
}
Uhhmm.. i cant seem to understand what you want to imply.. but from the way i see it.. if you want to have the keys of array 1 as value to array 2.. just do this code..
foreach($array1 as $key=>$val) {
$array2[] = $key;
}
This should grab the KEYS of array1 and insert it to your array2[].
Hope this helps you.. Cheers :)
This should print out what you need:
foreach($array2 as $key=>$val) {
echo $val;
foreach($array1 as $key2 => $val2){
if($key == $val2){
echo $val2;
}
}
echo '\n'; // new line
}