2

This is my array

Array
(
    [0] => Array
        (
            [0] => Music One
            [1] => Two
        )

    [1] => Array
        (
            [0] =>  C:\fakepath\Shape of You - Ed Sheeran (DJJOhAL.Com).mp3
            [1] => C:\fakepath\I m The One Ft Justin Bieber Quavo Chance The Rapper  Lil Wayne - DJ Khaled (DJJOhAL.Com).mp3
            [2] => 
        )

)

And I want like this

Array
(
    [0] => Array
        (
            [releasetrack_track_title] => Music One
            [releasetrack_mp3_demo] =>  C:\fakepath\Shape of You - Ed Sheeran (DJJOhAL.Com).mp3sample-DJ026-2.mp3

        )

    [1] => Array
        (
            [releasetrack_track_title] => Two
            [releasetrack_mp3_demo] => C:\fakepath\I m The One Ft Justin Bieber Quavo Chance The Rapper  Lil Wayne - DJ Khaled (DJJOhAL.Com).mp           
        )  

)

How is it possible i have also used function array_merge_recursive but i did not get output that i want.

Does anyone know about it then please share me code.

1

5 Answers 5

2

You need specific customization to manage your array, i had face same issue with customization, Please try below mention code, defiantly it will helpful,

<?php
$yourArr; //Your Requested array
$outputArr = [];

foreach ($yourArr as $i => $val) 
{   
    foreach ($val as $j => $con) 
    {
        if($j == 0) { $outputArr[$i]['releasetrack_track_title'] = $con; }

        if($j == 1) { $outputArr[$i]['releasetrack_mp3_demo'] = $con; }
    }
}

echo "<pre>"; print_r($outputArr); die();

?>

Sign up to request clarification or add additional context in comments.

Comments

2

You can try like this, live demo

$result = [];
foreach(range(0, count($array[0]) - 1) as $i)
{
  $result[] = array_combine(['releasetrack_track_title', 'releasetrack_mp3_demo'], array_column($array, $i));
}

Comments

1

You have no other way than just loop and to new array:

$newArray = [];

foreach ($oldArray as $index => $items) {
    switch ($index) {
        case 0:
            $key = 'releasetrack_track_title';
            break;
        case 1:
            $key = 'releasetrack_mp3_demo';
            break;
    }

    foreach ($items as $subIndex => $value) {
        $newArray[$subIndex][$key] = $value;
    }
}

Comments

0

Use foreach function over array[0] i.e. title array. Below is the code:

$newarr=array();
$music = Array(
[0] => Array
    (
        [0] => Music One
        [1] => Two
    )

[1] => Array
    (
        [0] =>  C:\fakepath\Shape of You - Ed Sheeran (DJJOhAL.Com).mp3
        [1] => C:\fakepath\I m The One Ft Justin Bieber Quavo Chance The Rapper  Lil Wayne - DJ Khaled (DJJOhAL.Com).mp3
        [2] => 
    )

)
foreach($music[0] as $key=>$value){
$newarr[$key]['releasetrack_track_title']=$value;
$newarr[$key]['releasetrack_mp3_demo']=$music[1][$key];
}
print_r($newarr);

Comments

-1

<?php
$arr = array(array(" Music One","C:\fakepath\Shape of You - Ed Sheeran (DJJOhAL.Com).mp3sample-DJ026-2.mp3"),array("Two", "C:\fakepath\I m The One Ft Justin Bieber Quavo Chance The Rapper  Lil Wayne - DJ Khaled (DJJOhAL.Com).mp"));
echo'<pre>';
print_r($arr);
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.