あなたはできません。これは無効な構文です。
ホバーあなたが行うことができます:
$key = 'a,b,c';
// or:
$key = serialize(array('a','b', 'c'));
// or many other things
そしてArrayAccess
またはArrayObject
(あなたが$key = 'a,b,c';
に固執するだろうLETの方法)を実装しますあなたの配列のようなクラスを実装するよりもを:
class MyArray extends ArrayAccess {
protected $data = array();
protected &_qetViaKey($key, &$exists, $createOnNonExisting = false){
// Parse keys
$keys = array();
if(strpos($key, ',') === false){
$keys[] = $key;
} else {
$keys = explode(',', $key);
}
// Prepare variables
static $null = null;
$null = null;
$exists = true;
// Browse them
$progress = &$this->data;
foreach($keys as $key){
if(is_array($progress)){
if(isset($progress[ $key])){
$progress = $progress[ $key];
} else {
if($createOnNonExisting){
$progress[ $key] = array();
$progress = $progress[ $key];
} else {
$exists = false;
break;
}
}
} else {
throw new Exception('$item[a,b] was already set to scalar');
}
}
if($exists){
return $progress;
}
return $null;
}
public offsetExists($key){
$exists = false;
$this->_getViaKey($key, $exists, false);
return $exists;
}
// See that we aren't using reference anymore in return
public offsetGet($key){
$exists = false;
$value = $this->_getViaKey($key, $exists, false);
if(!$exists){
trigger_error(... NOTICE ...);
}
return $value;
}
public offsetSet ($key, $val){
$exists = false;
$value = $this->_getViaKey($key, $exists, true);
$value = $val;
}
}
// And use it as:
$array = MyArray();
$array['a']['b']['c'] = 3;
$array['a,b,c'] = 3;
または実装関数:
public function &getArrayAtKey($array, $key){
// Similar to _qetViaKey
// Implement your own non existing key handling
}
?あるいは、あなたは、実験するのではなく、スプーンフィードで学ぶことを好むこれらの人々のひとりですか? –
あなたが達成しようとしていることを正確に理解するのは難しいです。 [配列のマニュアルを読む](http://php.net/manual/en/language.types.array.php) – Josh
はい、私はそれを試したが、いいえ、私はスプーンを与えられた人のようなものではない。 – Nealv