Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

php - 如何将值和键都推送到数组中(How to push both value and key into array)

Take a look at this code:

(看看这段代码:)

$GET = array();    
$key = 'one=1';
$rule = explode('=', $key);
/* array_push($GET, $rule[0] => $rule[1]); */

I'm looking for something like this so that:

(我正在寻找这样的东西,以便:)

print_r($GET);
/* output: $GET[one => 1, two => 2, ...] */

Is there a function to do this?

(有这个功能吗?)

(because array_push won't work this way)

((因为array_push不会这样工作))

  ask by Gal translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Nope, there is no array_push() equivalent for associative arrays because there is no way determine the next key.

(不,没有关联数组的array_push()等价物,因为无法确定下一个键。)

You'll have to use

(你必须使用)

$arrayname[indexname] = $value;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...