0

I want to hide array index number from returned array. I'm returning json_encode value but the problem is that it shows index number in result and i don't need those numbers. Function to return shuffle assoc array

function shuffle_assoc($my_array)
    {
        $keys = array_keys($my_array);

        shuffle($keys);

        foreach($keys as $key) {
            $new[$key] = $my_array[$key];
        }

        $my_array = $new;

        return $my_array;
    }

Main Code which return directory files names.

$dir  = ""; //directory path
$list = array(); //main array
$serveruri = "";
if(is_dir($dir)){
    if($dh = opendir($dir)){
        while(($file = readdir($dh)) != false){
            if($file == "." or $file == ".."){
                //...
            } else { //create object with two fields
                $list3 = array(
                    'video_url' => $serveruri.rawurlencode($file),
                    'video_title' => 'My Video Title'
                    );
                    //$fin_links = rand(($list3)); // To Shuffle the links
                array_push($list, $list3);
            }
        }
    }

    $return_array = $list;   
    echo json_encode(shuffle_assoc($return_array));
}

The Output returns

{
    "3": {
        "video_url": "my_video_url",
        "video_title": "My Video Title"
    },
    "5": {
        "video_url": "my_video_url",
        "video_title": "My Video Title"
    }  
}

Now I want to remove or hide array index numbers from output. Please help me to know how can i achieve this. Thanks for your time.

xcoders
  • 1
  • 1
  • 4

0 Answers0