PHP-在单个变量中存储多个值
例如,我有这样的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
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);
为什么不使用数组呢?再多一点信息就好了。为什么不使用数组呢?多了解一些信息就好了。