0

hello,
i have array

Array
(
    [certificate] => Array
        (
            ['name'] => Array
                (
                    [1] => 11
                    [2] => 22
                    [3] => 33
                    [5] => 55
                    [6] => 66
                )

            ['date'] => Array
                (
                    [1] => 1111
                    [2] => 2222
                    [3] => 3333
                    [5] => 5555
                    [6] => 6666
                )
)

I want to make echo name=>1 value with date=>1 value.

though,Indexes of both array are same but are not in serial.
like in above case we have missed 4th index.
so how to merger these two?

3
Contributors
4
Replies
16
Views
3 Years
Discussion Span
Last Post by niranga
0

Your question is not terribly clear but are you trying to do something like this?

$names = $certs['name'];
$dates = $certs['date'];

$keys = array_keys($names);

$out = '';
foreach($keys as $key)
{
 if (!array_key_exists($dates,$key)) continue;
 $out .= $names[$key].'='.$dates[$key];
}

echo $out;
0

Your requirment can be achieved by a foreach loop. I just used an echo for the merge, but u can insert the values to another array as you wish.

<?php
    $arr = Array
    (
        "certificate" => Array
        (
            "name" => Array
            (
                1 => 11,
                2 => 22,
                3 => 33,
                5 => 55,
                6 => 66
            ),
            "date" => Array
            (
                1 => 1111,
                2 => 2222,
                3 => 3333,
                5 => 5555,
                6 => 6666
            )
        )
    );

    foreach($arr["certificate"]["name"] as $key => $value)
    {
        echo $arr["certificate"]["name"][$key] ." - ". $arr["certificate"]["date"][$key] . "<br/>";
    }
?>
0

Hello niranga,
Actually above this is print_r($_POST) value of form.

so it is not like

 $arr = Array
(
"certificate" => Array
(
"name" => Array
(

but ots like

Array
(
[certificate] => Array
(
['name'] => Array
(

for for applying for loop for key value paire is not applicable here.
it says
"Undefined index: name " for

foreach($_POST["certificate"]["name"] as $key => $value)
0

Hi Priti_P
The print_r displays the elements in your array in the given format, but its just for display. Try printing my variable, i.e. $arr using print_r. It gives you the same output. Will you be able to post the var_dump($_POST) result?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.