$prices has the following values
Array
(
[0] => 824.2776
[1] => 1586.5128
[2] => 2277.8424
[3] => 2902.698
[4] => 3465.5112
[5] => 3957.4188
)
I also have some voucher codes in $vArray which looks like this:
Array
(
[voucher1] => 30
[voucher2] => 40
)
I would like to create prices which have a percentage subtracted. In this case 30% and 40% ... just not sure how.
foreach($prices as $price){
foreach($vArray as $key => $value){
$prices[] = ($value / $price) * 100;
}
}
The above foreach is creating these additional array items in $prices
[6] => 3.6395505591805
[7] => 1.8909396759988
[8] => 1.3170358054622
[9] => 1.0335212274925
[10] => 0.86567315090484
[11] => 0.75806988130748
$prices = [
100,
824.2776,
1586.5128,
2277.8424,
2902.698,
3465.5112,
3957.4188
];
$vArray = [
'voucher1' => 30,
'voucher2' => 40,
];
foreach ($prices as $price) {
foreach ($vArray as $voucherId => $percentage){
$prices[] = $price * (1 - ($percentage / 100));
}
}
print_r($prices);
Output:
Array
(
[0] => 100
[1] => 824.2776
[2] => 1586.5128
[3] => 2277.8424
[4] => 2902.698
[5] => 3465.5112
[6] => 3957.4188
[7] => 70
[8] => 60
[9] => 576.99432
[10] => 494.56656
...
[20] => 2374.45128
)
Related
Array
(
[0] => Array
(
[package] => LTE_15AGB
[value] => Array
(
[0] => 52690
[1] => 24700
[2] => 43972
[3] => 506417
[4] => 488125
[5] => 935918
[6] => 1322816
[7] => 1189040
[8] => 2805279
[9] => 2764825
[10] => 1688294
[11] => 1228812
[12] => 2232345
[13] => 3356143
[14] => 1193213
[15] => 167589
[16] => 1373104
[17] => 691411
[18] => 1398647
[19] => 5
)
)
[1] => Array
(
[package] => LTE_15AGB_NT
[value] => Array
(
[0] => 953370
[1] => 151168
[2] => 37605
[3] => 428769
[4] => 755222
[5] => 1146719
[6] => 494289
[7] => 889002
[8] => 307200
[9] => 127972
[10] => 2764815
[11] => 1426224
[12] => 262669
[13] => 648757
[14] => 1485
[15] => 1202
[16] => 998
[17] => 1
)
)
)
This is what I have tried:
$tmp = array();
foreach($arrayName as $arg){
$tmp[$arg['package']][] = $arg['value'];
}
$output = array();
foreach($tmp as $type => $labels){
$output[] = array( 'package' => $type, 'value' => $labels, );
}
print_r(($output))
Try this:
foreach ($your_array as $subarr) {
echo $subarr[package]." minimum = ";
echo min($subarr[value])." and maximum = ";
echo max($subarr[value])."<br>";
}
this will output each package name together with the minimum and maximum values.
Simply use the min() and max() functions.
Your code:
foreach(array_column($array, 'value') as $key => $values){
echo PHP_EOL . 'SubArray '. $key .' min = '. min($values) . ' and max value = '. max($values);
}
output is:
SubArray 0 min = 5 and max value = 3356143
SubArray 1 min = 1 and max value = 2764815
References:
PHP min() manual
PHP max()) manual
PHP array_column
manual
Live demo: https://eval.in/941702
#Arebhy Sri, You should search about array in php, It's like basic problem.
$finalArray = [];
foreach ($mainArr as $subArr){
$array = $subArr['value'];
sort($array);
$tempArray['minimum'] = reset($array);
$tempArray['maximum'] = end($array);
$tempArray['package'] = $subArr['package'];
$finalArray[] = $tempArray;
}
$finalArray //you can use
I am using simple foreach and two functions of array reset() and end().
reset(): Returns the value of the first array element, or FALSE if the array is empty.
end(): Returns the value of the last element or FALSE for empty array.
I have an array which holds some articles of a website. The problem is: when the same article is in 2 different categories it only shows 1. In this example the categories are 'Service' and 'Sales'.
If the article is duplicate and the category is 'Sales' I want 1 of them to change to 'Service' and vice versa.
The array I got now(3 & 4 as duplicates and 7 & 8):
Array
(
[0] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/38BbjLmVJXk
[3] => Park assist
)
[1] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/3lGfTZdVK1s
[3] => Multi Collision braking system
)
[2] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/6mgDraWpGvE
[3] => Area view
)
[3] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[4] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[5] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/N0fa4dUBkvE
[3] => Trailer assist
)
[6] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/NCNDyW6Yr1g
[3] => Ruitenwissers
)
[7] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
[8] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
)
The array I want to accomplish (No duplicates anymore and the values changed):
Array
(
[0] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/38BbjLmVJXk
[3] => Park assist
)
[1] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/3lGfTZdVK1s
[3] => Multi Collision braking system
)
[2] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/6mgDraWpGvE
[3] => Area view
)
[3] => Array
(
[0] => Service
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[4] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[5] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/N0fa4dUBkvE
[3] => Trailer assist
)
[6] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/NCNDyW6Yr1g
[3] => Ruitenwissers
)
[7] => Array
(
[0] => Sales
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
[8] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
)
What I tried:
$length = count ($sorted);
for ($c = 0; $c < $length; $c++) {
$check_array = $sorted[$c];
for ($x = 0; $x < $length; $x++) {
$compare_array = $sorted[$x];
if ($x != $i){
if($check_array[2] == $compare_array[2] && $check_array[0] == $compare_array[0]){
//print_r ($check_array);
//print_r ($compare_array);
if($check_array[0] == 'Sales'){
$compare_array[0] = 'Service';
}
if($check_array[0] == 'Service'){
$compare_array[0] = 'Sales';
}
}
}
}
}
Any help will be much appreciated.
Put your data in $array variable and try it:
$hash = array_map( function ( $value ) { return md5( implode( $value ) ); } , $array);
$keys = array_keys( array_diff_assoc( $hash, array_unique( $hash ) ) );
foreach( $keys as $key )
$array[ $key ][0] = $array[ $key ][0] == 'Service' ? 'Sales' : 'Service';
If the order is not important for you, you can use array_multisort, array_column and array_walk:
$replacements = [
'Sales' => 'Service',
'Service' => 'Sales'
];
// Sort array by youtube url.
array_multisort($array, array_column($array, 2));
array_walk($array, function (&$curr, $_, &$prev) use ($replacements) {
if (
$prev !== null
&& $prev[2] === $curr[2]
) {
$curr[0] = $replacements[$curr[0]];
}
$prev = $curr;
}, null);
Here is working demo.
Here I have a written some code, you can try it.
<?php
$array = [
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/38BbjLmVJXk',
3 => 'Park assist',
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/3lGfTZdVK1s',
3 => 'Multi Collision braking system'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/6mgDraWpGvE',
3 => 'Area view'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/II68oVm4zro',
3 => 'Lane Assist'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/II68oVm4zro',
3 => 'Lane Assist'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/N0fa4dUBkvE',
3 => 'Trailer assist'
],
[
0 => 'Service',
1 => 'veilig-op-de-weg',
2 => 'www.youtube.com/video/NCNDyW6Yr1g',
3 => 'Ruitenwissers'
],
[
0 => 'Service',
1 => 'veilig-op-de-weg',
2 => 'www.youtube.com/video/PJEC-yqUwzE',
3 => 'Bandenafdichtset'
],
[
0 => 'Service',
1 => 'veilig-op-de-weg',
2 => 'www.youtube.com/video/PJEC-yqUwzE',
3 => 'Bandenafdichtset'
]
];
/**
* #param $firstIndexValue
* #param $thirdIndexValue
* #param $searchArray
* #return bool
*/
function isExistValue($firstIndexValue, $thirdIndexValue, $searchArray)
{
foreach ($searchArray as $element) {
if ($firstIndexValue == $element[0] && $thirdIndexValue == $element[3]) {
return true;
}
}
return false;
}
$newArray = [];
foreach ($array as $arr) {
$isExist = isExistValue($arr[0], $arr[3], $newArray);
if ($isExist) {
if ($arr[0] == 'Sales') {
$arr[0] = 'Service';
} elseif ($arr[0] == 'Service') {
$arr[0] = 'Sales';
}
}
$newArray[] = $arr;
}
var_dump($newArray);
This is the result of array after i build it using array_push function from mssql result.
Array
(
[0] => Array
(
[STICKER] => FALCON
[MONTH] => 1
[JUM] => 65826210.00
)
[1] => Array
(
[STICKER] => FALCON
[MONTH] => 2
[JUM] => 68070573.00
)
[2] => Array
(
[STICKER] => FALCON
[MONTH] => 3
[JUM] => 99053067.60
)
[3] =>
[4] => Array
(
[STICKER] => HRD
[MONTH] => 2
[JUM] => 1521400.00
)
[5] => Array
(
[STICKER] => HRD
[MONTH] => 3
[JUM] => 2093200.00
)
)
I need to convert array above into this structure:
Array
(
[0] => Array
(
[0] =>
[1] => 1
[2] => 2
[3] => 3
)
[1] => Array
(
[0] => FALCON
[1] => 65826210.00
[2] => 68070573.00
[3] => 99053067.60
)
[2] => Array
(
[0] => HRD
[1] => 0
[2] => 1521400.00
[3] => 2093200.00
)
)
Note:
Array[0] values would be 1,2,3 (this is actualy month, i just input up to 3 in order to get the code not too long. but it will be up to 12 (Jan - Dec)).
If from original array, there is none value (example from array[3]), then it will be convert to new array[2]->[1] with value 0.
Any help would be very appreciated.
Thanks all!.
Try this,
If any month is not mentioned from stickers the jum considered as 0,
$array = array(
array('STICKER' => 'FALCON', 'MONTH' => 1, 'JUM' => 65826210.00),
array('STICKER' => 'FALCON', 'MONTH' => 2, 'JUM' => 68070573.00),
array('STICKER' => 'FALCON', 'MONTH' => 3, 'JUM' => 99053067.60),
array(),
array('STICKER' => 'HRD', 'MONTH' => 2, 'JUM' => 1521400.00),
array('STICKER' => 'HRD', 'MONTH' => 3, 'JUM' => 2093200.00),
);
$result[0][] = '';
foreach ($array as $key => $res) {
if (!empty($res)) {
$result[0][$res['MONTH']] = $res['MONTH'];
$result1[$res['STICKER']][$res['MONTH']] = $res['JUM'];
}
}
foreach ($result1 as $key => $res) {
$fin = array();
foreach ($res as $key1 => $re) {
foreach ($result[0] as $key2 => $month) {
if ($month != '') {
if (array_key_exists($month, $res)) {
if (!array_key_exists($month, $fin) && $month == $key1) {
$fin[$month] = $re;
}
} else {
$fin[$month] = 0;
}
}
}
}
$result[] = array_merge(array($key), $fin);
}
echo'<pre>';
print_r($result);
echo'<pre>';
Result:
Array
(
[0] => Array
(
[0] =>
[1] => 1
[2] => 2
[3] => 3
)
[1] => Array
(
[0] => FALCON
[1] => 65826210
[2] => 68070573
[3] => 99053067.6
)
[2] => Array
(
[0] => HRD
[1] => 0
[2] => 1521400
[3] => 2093200
)
)
I hope this is used to achieve your output(you mentioned in above question)!!
try something like this
not the issue with the empty array i could not understand how the program would know that it is STICKER HRD so it will be filled with zero.But you could later check if every month "isset" and if it is not act as it is zero
$arr1=array(
array('STICKER'=>'FALCON','MONTH'=>1,'JUM'=>65826210.00),
array('STICKER'=>'FALCON','MONTH'=>2,'JUM'=>68070573.00),
array('STICKER'=>'FALCON','MONTH'=>3,'JUM'=>99053067.60),
array(),
array('STICKER'=>'HRD','MONTH'=>2,'JUM'=>1521400.00),
array('STICKER'=>'HRD','MONTH'=>3,'JUM'=>2093200.00),
);
$arr2=array();
$arr3=array();
$arr2[0][0]="";
foreach($arr1 as $key => $val){
if(!empty($val)){
$arr2[0][$val['MONTH']]=$val['MONTH'];
//group each STICKER
$arr3[$val['STICKER']][]=$val['JUM'];
}
}
//transfer the grouped data to arr2
foreach($arr3 as $key => $val){
$tmp_arr=array($key);
$arr2[]=array_merge($tmp_arr,$val);
}
print_r($arr2);
I have following array with php code
I could not find where I am mistaken
I'm trying to filter some of these array results and delete them. When I try to list them I could not succeded
array (
0 => 'do-update.php',
1 => 'sitemap.xml',
2 => 'sitemap.xml.gz',
3 => 'wp-config.php',
'wp-content' =>
array (
'uploads' =>
array (
2013 =>
array (
'05' =>
array (
0 => 'kabeduvarkad-1024x768.jpg',
1 => 'kabeduvarkad-150x150.jpg',
2 => 'kabeduvarkad-300x225.jpg',
3 => 'kabeduvarkad-940x198.jpg',
4 => 'kabeduvarkad.jpg',
5 => 'kabeduvarkad1-1000x288.jpg',
6 => 'kabeduvarkad1-1024x768.jpg',
7 => 'kabeduvarkad1-150x150.jpg',
8 => 'kabeduvarkad1-300x225.jpg',
9 => 'kabeduvarkad1-400x300.jpg',
10 => 'kabeduvarkad1.jpg',
11 => 'kabeduvarkad2-1000x288.jpg',
12 => 'kabeduvarkad2-1024x768.jpg',
13 => 'kabeduvarkad2-150x150.jpg',
14 => 'kabeduvarkad2-300x225.jpg',
15 => 'kabeduvarkad2-400x300.jpg',
16 => 'kabeduvarkad2.jpg',
),
10 =>
array (
),
),
2014 =>
array (
'02' =>
array (
),
),
),
),
'wp-update' =>
array (
0 => 'wp-update.tar',
1 => 'wp-update.tar.gz',
2 => 'wp-update1.tar',
3 => 'wp-update1.tar.gz',
),
4 => 'wp-update.tar.gz',
)
This is my function
function listArrayRecursive($array_name, $ident = ''){
$result = array();
foreach ($array_name as $k => $v){
if (is_array($v)){
$result[] = listArrayRecursive($v, $ident.'/'.$k);
}else{
$result[] = $ident. '/' . $v . '<br>';
}
}
return $result;
}
I have following result
Array
(
[0] => /do-update.php<br>
[1] => /sitemap.xml<br>
[2] => /sitemap.xml.gz<br>
[3] => /wp-config.php<br>
[4] => Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => /wp-content/uploads/2013/05/kabeduvarkad-1024x768.jpg<br>
[1] => /wp-content/uploads/2013/05/kabeduvarkad-150x150.jpg<br>
[2] => /wp-content/uploads/2013/05/kabeduvarkad-300x225.jpg<br>
[3] => /wp-content/uploads/2013/05/kabeduvarkad-940x198.jpg<br>
[4] => /wp-content/uploads/2013/05/kabeduvarkad.jpg<br>
[5] => /wp-content/uploads/2013/05/kabeduvarkad1-1000x288.jpg<br>
[6] => /wp-content/uploads/2013/05/kabeduvarkad1-1024x768.jpg<br>
[7] => /wp-content/uploads/2013/05/kabeduvarkad1-150x150.jpg<br>
[8] => /wp-content/uploads/2013/05/kabeduvarkad1-300x225.jpg<br>
[9] => /wp-content/uploads/2013/05/kabeduvarkad1-400x300.jpg<br>
[10] => /wp-content/uploads/2013/05/kabeduvarkad1.jpg<br>
[11] => /wp-content/uploads/2013/05/kabeduvarkad2-1000x288.jpg<br>
[12] => /wp-content/uploads/2013/05/kabeduvarkad2-1024x768.jpg<br>
[13] => /wp-content/uploads/2013/05/kabeduvarkad2-150x150.jpg<br>
[14] => /wp-content/uploads/2013/05/kabeduvarkad2-300x225.jpg<br>
[15] => /wp-content/uploads/2013/05/kabeduvarkad2-400x300.jpg<br>
[16] => /wp-content/uploads/2013/05/kabeduvarkad2.jpg<br>
)
[1] => Array
(
)
)
[1] => Array
(
[0] => Array
(
)
)
)
)
[5] => Array
(
[0] => /wp-update/wp-update.tar<br>
[1] => /wp-update/wp-update.tar.gz<br>
[2] => /wp-update/wp-update1.tar<br>
[3] => /wp-update/wp-update1.tar.gz<br>
)
[6] => /wp-update.tar.gz<br>
)
Expected Result is
Array
(
[0] => /do-update.php<br>
[1] => /sitemap.xml<br>
[2] => /sitemap.xml.gz<br>
[3] => /wp-config.php<br>
[4] => /wp-content/uploads/2013/05/kabeduvarkad-1024x768.jpg<br>
[5] => /wp-content/uploads/2013/05/kabeduvarkad-150x150.jpg<br>
[6] => /wp-content/uploads/2013/05/kabeduvarkad-300x225.jpg<br>
[7] => /wp-content/uploads/2013/05/kabeduvarkad-940x198.jpg<br>
[8] => /wp-content/uploads/2013/05/kabeduvarkad.jpg<br>
[9] => /wp-content/uploads/2013/05/kabeduvarkad1-1000x288.jpg<br>
[10] => /wp-content/uploads/2013/05/kabeduvarkad1-1024x768.jpg<br>
[11] => /wp-content/uploads/2013/05/kabeduvarkad1-150x150.jpg<br>
[12] => /wp-content/uploads/2013/05/kabeduvarkad1-300x225.jpg<br>
[13] => /wp-content/uploads/2013/05/kabeduvarkad1-400x300.jpg<br>
[14] => /wp-content/uploads/2013/05/kabeduvarkad1.jpg<br>
...
[110] => /wp-update/wp-update.tar<br>
[111] => /wp-update/wp-update.tar.gz<br>
[112] => /wp-update/wp-update1.tar<br>
[113] => /wp-update/wp-update1.tar.gz<br>
[114] => /wp-update.tar.gz<br>
)
You can do it like this:
<?php
// Dummy data source
$data = array(
'/do-update.php',
'/sitemap.xml',
'/sitemap.xml.gz',
'/wp-config.php',
array(
array(
array(
'/wp-content/uploads/2013/05/kabeduvarkad-1024x768.jpg',
'/wp-content/uploads/2013/05/kabeduvarkad-150x150.jpg',
'/wp-content/uploads/2013/05/kabeduvarkad-300x225.jpg<br>'
)
)
)
);
// Helper function
function getFiles($data, &$fileList) {
foreach ($data as $dataItem) {
if (is_array($dataItem))
getFiles($dataItem, $fileList);
else
$fileList[] = $dataItem;
}
}
// Debug
echo "<b>Orignal Array</b>";
var_dump($data);
echo "<hr>";
// Helper function usage
echo "<b>Parsed Array</b>";
$fileList = array();
getFiles($data, $fileList);
var_dump($fileList);
?>
Output:
Ok use this function its working
$all=array();
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
foreach($it as $v) {
$all[]=$v;
}
print_r($all);
With $var[] = you basically say that you want to add a new Element to $var with an incremented key.
Your Recursive frunction returns an array.
So this array is assigned as a new element in your array.
But what you want is a flat array.
Instead of adding an array to your array like this:
if (is_array($v)){
$result[] = listArrayRecursive($v, $ident.'/'.$k);
Merge the existing arrays like this:
if (is_array($v)){
$tmpResult = listArrayRecursive($v, $ident.'/'.$k);
$result = array_merge($result, $tmpResult);
You can see a working example here.
Ive seen a few examples by using array_values, but cant quite make out how to get it to work...
I have an associative array thats passed via POST, I need to convert it into a indexed array...
My print_r($_POST) gives me this... I need all of this put into an indexed array :)
Array (
[fieldnames] => 36771X21X198|36771X21X199|36771X21X200|36771X21X201|36771X21X202
[36771X21X198] => 3434343
[display36771X21X198] => on
[36771X21X199] => 5656565
[display36771X21X199] => on
[36771X21X200] => 89898989
[display36771X21X200] => on
[36771X21X201] => 90909090
[display36771X21X201] => on
[36771X21X202] => 12121212
[display36771X21X202] => on
[move] => movesubmit
[move2] => ONLINE Submit
[thisstep] => 1
[sid] => 36771
[token] => 1234567890
)
Observe this amazing way to convert your $_POST into a numerically indexed array:
$numerical = array_values($_POST);
but what if you want to preserve your keys? Perhaps you want something like this?
$numerical = array();
$sep = ':';
foreach($_POST as $k=>$v)
{
$numerical[] = $k.$sep.$v;
}
$numerical will then have:
Array
(
[0] => fieldnames:36771X21X198|36771X21X199|36771X21X200|36771X21X201|36771X21X202
[1] => 36771X21X198:3434343
[2] => display36771X21X198:on
[3] => 36771X21X199:5656565
[4] => display36771X21X199:on
[5] => 36771X21X200:89898989
[6] => display36771X21X200:on
[7] => 36771X21X201:90909090
[8] => display36771X21X201:on
[9] => 36771X21X202:12121212
[10] => display36771X21X202:on
[11] => move:movesubmit
[12] => move2:ONLINE Submit
[13] => thisstep:1
[14] => sid:36771
[15] => token:1234567890
)
or, for my final example:
$fieldnames_original = explode('|', $_POST['fieldnames']);
$fieldnames_actual = array();
$values = array();
foreach($_POST as $k=>$v)
{
if($k!='fieldnames')
{
$fieldnames_actual[] = $k;
$values[] = $v;
}
}
which will set 3 arrays:
$fieldnames_original:
Array
(
[0] => 36771X21X198
[1] => 36771X21X199
[2] => 36771X21X200
[3] => 36771X21X201
[4] => 36771X21X202
)
$fieldnames_actual:
Array
(
[0] => 36771X21X198
[1] => display36771X21X198
[2] => 36771X21X199
[3] => display36771X21X199
[4] => 36771X21X200
[5] => display36771X21X200
[6] => 36771X21X201
[7] => display36771X21X201
[8] => 36771X21X202
[9] => display36771X21X202
[10] => move
[11] => move2
[12] => thisstep
[13] => sid
[14] => token
)
and $values:
Array
(
[0] => 3434343
[1] => on
[2] => 5656565
[3] => on
[4] => 89898989
[5] => on
[6] => 90909090
[7] => on
[8] => 12121212
[9] => on
[10] => movesubmit
[11] => ONLINE Submit
[12] => 1
[13] => 36771
[14] => 1234567890
)
function
function array_default_key($array) {
$arrayTemp = array();
$i = 0;
foreach ($array as $key => $val) {
$arrayTemp[$i] = $val;
$i++;
}
return $arrayTemp;
}
Pass the associative array as a parameter and it will convert into the default index of the array. For example: we have Array('2014-04-30'=>43,'2014-04-29'=>41) after the call to the function the array will be Array(0=>43,1=>41).
Recursive assoc to indexed converter tested on a small array.
function assoc2indexedMulti($arr) {
// initialize destination indexed array
$indArr = array();
// loop through source
foreach($arr as $val) {
// if the element is array call the recursion
if(is_array($val)) {
$indArr[] = assoc2indexedMulti($val);
// else add the value to destination array
} else {
$indArr[] = $val;
}
}
return $indArr;
}