问题描述
我很好奇,比什么都重要 - 是否有可能通过某种索引获得PHP值,即$ _POST ['foo']?即$ _POST [0]?
Im curious, more than anything - is it possible to get a PHP value posted i.e. $_POST['foo'] via some kind of indexing? i.e. $_POST[0]?
($ _ POST [0]不起作用)
($_POST[0] does not work by the way)
推荐答案
不,这是不可能的:你不能通过数字索引从关联数组中获取值(因为,如,PHP不区分索引数组和关联数组。)
No, it's not possible: you cannot fetch values from an associative array by numeric indexes (because, as clearly noted in the doc, PHP does not distinguish between indexed and associative arrays).
这就是为什么有些功能(例如及其兄弟姐妹)返回数组需要一个额外的参数来控制返回数组中索引的类型:numeric( FETCH_NUM
),string( FETCH_ASSOC
)或两者( FETCH_BOTH
,默认值)。 )
That's why some functions (PDOStatement::fetch and its siblings, for example) that return arrays take an additional param to control the 'type' of indexes in the array returned: numeric (FETCH_NUM
), string (FETCH_ASSOC
) or both (FETCH_BOTH
, the default value). )
最接近重建索引:
$myPost = array_values($_POST);
这篇关于按索引获取PHP $ _POST值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!