var_dump

(PHP 3 >= 3.0.5, PHP 4, PHP 5)

var_dump -- Dumps information about a variable

Описание

void var_dump ( mixed expression [, mixed expression [, ...]] )

This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.

In PHP 5 only public, private and protected properties of objects will be returned in the output.

Подсказка: Как и с любой другой функцией, осуществляющей вывод непосредственно в браузер, вы можете использовать функции контроля вывода, чтобы перехватывать выводимые этой функцией данные и сохранять их, например, в string.

Список параметров

expression

The variable you want to export.

Возвращаемые значения

Эта функция не возвращает значения после выполнения.

Примеры

Пример 1. var_dump() example

<?php
$a
= array(1, 2, array("a", "b", "c"));
var_dump($a);
?>

Результат выполнения данного примера:

array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  array(3) {
    [0]=>
    string(1) "a"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "c"
  }
}
<?php

$b
= 3.1;
$c = true;
var_dump($b, $c);

?>

Результат выполнения данного примера:

float(3.1)
bool(true)

Смотрите также

var_export()
print_r()



var_dump
andre at webkr dot de
04-Oct-2005 02:45
var_dump prefixes the variable type with & if the variable has more than one reference.
This is only true for variables that are part of an array, not for scalar types.

Example:
<?php
$a
['foo'] = 'other';
$a['bar'] = 'i_have_ref';
$b =& $a['bar'];

var_dump($a);
var_dump($b);
?>

Result:
array(2) {
 ["foo"]=>
  string(5) "other"
 ["bar"]=>
  &string(10) "i_have_ref"
}
string(10) "i_have_ref"
ospinto at hotmail dot com
06-Aug-2005 09:43
Just created this neat class that dumps a variable in a colored tabular structure similar to the cfdump tag in Coldfusion. Very easy to use and makes it so much easier to see the contents of variable. For examples and download, visit http://dbug.ospinto.com
edwardzyang at thewritingpot dot com
20-Mar-2005 02:06
If you're like me and uses var_dump whenever you're debugging, you might find these two "wrapper" functions helpful.

This one automatically adds the PRE tags around the var_dump output so you get nice formatted arrays.

<?php

function var_dump_pre($mixed = null) {
  echo
'<pre>';
 
var_dump($mixed);
  echo
'</pre>';
  return
null;
}

?>

This one returns the value of var_dump instead of outputting it.

<?php

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

?>

Fairly simple functions, but they're infinitely helpful (I use var_dump_pre() almost exclusively now).
anon
28-Jan-2005 06:31
var_dump(get_defined_vars());
will dump all defined variables to the browser.

<unsetvar_export>
 Last updated: Tue, 15 Nov 2005