Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-在单个变量中存储多个值_Php_Variables - Fatal编程技术网

PHP-在单个变量中存储多个值

PHP-在单个变量中存储多个值,php,variables,Php,Variables,例如,我有这样的PHP代码 if ($rating_count == $rating_notnull) { $returnValue = 1; } if($project_count == $project_notnull) { $returnValue = 2; } 现在,我想将两个变量值存储到一个变量中?数组可用于保存多个值。他们可以有钥匙也可以没有 <?php $x = array(); $x[] = 'Some Val

例如,我有这样的PHP代码

if ($rating_count == $rating_notnull) {
        $returnValue =  1;
    }
    if($project_count == $project_notnull) {
        $returnValue = 2;
    }

现在,我想将两个变量值存储到一个变量中?

数组可用于保存多个值。他们可以有钥匙也可以没有

<?php

$x = array();

$x[] = 'Some Value';
$x[] = 'Another value';

var_dump($x);

$x = array();

$x['name'] = 'Anil';
$x['other name'] = 'Del Boy';

var_dump($x);

$x = array(
    'Name' => 'Batman',
    'Status' => 'Busy',
    'etc' => 'etc',
);

var_dump($x);

数组可用于保存多个值。他们可以有钥匙也可以没有

<?php

$x = array();

$x[] = 'Some Value';
$x[] = 'Another value';

var_dump($x);

$x = array();

$x['name'] = 'Anil';
$x['other name'] = 'Del Boy';

var_dump($x);

$x = array(
    'Name' => 'Batman',
    'Status' => 'Busy',
    'etc' => 'etc',
);

var_dump($x);

如其他注释所述,最有效的方法是使用数组存储这些值

但是,如果您确实希望将其存储在单个变量中,则可以使用

这将在爆炸时以数组形式输出,但允许将其存储到一个变量中

$str = "Hello, this, is, a, variable";
explode(",", $str);

如其他注释所述,最有效的方法是使用数组存储这些值

但是,如果您确实希望将其存储在单个变量中,则可以使用

这将在爆炸时以数组形式输出,但允许将其存储到一个变量中

$str = "Hello, this, is, a, variable";
explode(",", $str);

为什么不使用数组呢?再多一点信息就好了。为什么不使用数组呢?多了解一些信息就好了。