Home  >  Article  >  Backend Development  >  The php array is converted into something like this

The php array is converted into something like this

WBOY
WBOYOriginal
2016-10-12 10:04:101087browse

An array like thisArray ( [0] => a [1] => s [2] => d [3] => f ) is converted into Array ( '0' => ' a','1' => 's', '2' => 'd', '3' => 'f' ) Is it possible? Please give me guidance

In fact, the process is as follows: two strings $atr = 1,2,3,4 $str=a,b,c,f are converted into array array in one-to-one correspondence ('1'=>'a','2' =>'b','3'=>'c','4'=>'f')

And print out array('1'=>'a','2'=>'b','3'=>'c','4'=>'f'), don't know this Is it easy to understand?

Reply content:

An array like this

Array ( [0] => a [1] => s [2] => d [3] => f ) is converted into Array ( '0' => ' a','1' => 's', '2' => 'd', '3' => 'f' ) Is it possible? Please give me guidance

In fact, the process is as follows: two strings $atr = 1,2,3,4 $str=a,b,c,f are converted into array array in one-to-one correspondence ('1'=>'a','2' =>'b','3'=>'c','4'=>'f')

And print out array('1'=>'a','2'=>'b','3'=>'c','4'=>'f'), don't know this Is it easy to understand?

The php array is converted into something like thisThis of yours cannot be used

It should not work

If the key of the array can be converted into Int, it will be converted into a number

You can refer to the manual
http://php.net/manual/zh/lang...

<code>Array ( [0] => a [1] => s [2] => d [3] => f )

</code>
When such an array display appears, it is generally a friendly display of dump under tp. It's not an array.

<code>$tmp = array( '0' => 'a','1' => 's', '2' => 'd', '3' => 'f' );
var_dump($tmp);
</code>

The above code shows:

<code>Array ( [0] => a [1] => s [2] => d [3] => f )
</code>

====================dump source code============================

<code> /**
 * 浏览器友好的变量输出
 * @param mixed $var 变量
 * @param boolean $echo 是否输出 默认为true 如果为false 则返回输出字符串
 * @param string $label 标签 默认为空
 * @return void|string
 */
public static function dump($var, $echo = true, $label = null)
{
    $label = (null === $label) ? '' : rtrim($label) . ':';
    ob_start();
    var_dump($var);
    $output = ob_get_clean();
    $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
    if (IS_CLI) {
        $output = PHP_EOL . $label . $output . PHP_EOL;
    } else {
        if (!extension_loaded('xdebug')) {
            $output = htmlspecialchars($output, ENT_QUOTES);
        }
        $output = '<pre class="brush:php;toolbar:false">' . $label . $output . '
'; } if ($echo) { echo ($output); return null; } else { return $output; } }

How did you arrive at this array? ? ! !

Array ( [0] => a [1] => s [2] => d [3] => f )


Are there commas between parameters?

For example, Array ( [0] => a ,[1] => s, [2] => d ,[3] => f );

But this is also an empty array?

The php array is converted into something like this

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn