0

Hello. I am new to PHP/MYSQL. My array looks like this:

Array
(
    [1] => item1
    [2] => 1tem2
    [3] => item3
    [4] => item4
    [5] => item5
    [6] => item6
)
Array
(
    [7] => item1
    [8] => item2
)
Array
(
    [9] => item1
    [10] => 1tem2
    [11] => item3

I want to loop through each item in each array and for each item i create a new row that looks like this

Array
(
[1]=>item1
[2]=>item1a
[3]=>item2
[4]=>item2a

etc
i have tried achieving this by writing the following

foreach($item as $dkey => $dvavalue){
foreach($dvalue as $value){
for($i=0;$i<$value; $i++){
#some code here
}
}
}   

As i have indicated iam new to programming and also in PHP. I know this might seem like a trivial question but your suggestions on how best to solve this are welcome

2
Contributors
2
Replies
11
Views
1 Year
Discussion Span
Last Post by Gurjit_2
0

This is what i have tried

    foreach($item as $dkey => $dvavalue){
    foreach($dvalue as $value){
    for($i=0;$i<=$value; $i++){
        #some code here
        if($i==0){
            $value = "item";
        }
        else{
        $x=$i +1;
        $value = $value . "_$x";
        }
    }
    }
    }   
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.