saqib kifayat
saqib kifayat

Reputation: 166

how to store var_dump data in variables

I have the following var_dump data in my console. i want to store them in variables.

    array(1) {
      ["pupload"]=>
       array(5) {
        ["name"]=>
        string(11) "profile.jpg"
        ["type"]=>
        string(10) "image/jpeg"
        ["tmp_name"]=>
        string(45) "C:\Users\pcname\AppData\Local\Temp\phpAF1C.tmp"
        ["error"]=>
        int(0)
        ["size"]=>
        int(114348)
  }
}

UPDATE

My code

    $variable =   var_dump($_FILES);
    echo $variable;

Upvotes: 1

Views: 534

Answers (3)

Peter Lane
Peter Lane

Reputation: 41

If you know what the elements of that array are and you know what variables you need to create from all the elements, I think the shortest answer is to use this, given PHP version >= 7.1:

list($name, $type, $tmp_name, $error, size) = $_FILES;

Upvotes: 0

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72269

As you said :- I want to store "name", "type" and "tmp_name" in variables

And you tell that your variable is $_FILES. So do like below:-

$name  = $_FILES['pupload']['name']; 
$type  = $_FILES['pupload']['type']; 
$tmp_name = $_FILES['pupload']['tmp_name']; 
echo $name.' : '.$type.' : '.$tmp_name;

Upvotes: 1

Akhil VL
Akhil VL

Reputation: 357

This can do

function var_dump_ret($mixed = null) {
 ob_start();
 var_dump($mixed);
 $content = ob_get_contents();
 ob_end_clean();
 return $content;
}

Upvotes: 1

Related Questions