T
T
Timofey Mikhailov2017-05-16 07:48:15
PHP
Timofey Mikhailov, 2017-05-16 07:48:15

Why doesn't it return the value of the associative array?

php code ===========
$e1 = array(
"t1" => 112,
"t2" => 113);
$e2 = array(
"s1" => 227,
"s2" => 228);
$e = array(
"one" => $e1,
"two" => $e2);
echo ""
===================
* Outputs:
--e1
---t1: 112
---t2: 113
--e2
---s1: 227
- --s2: 228
Next, I'd like to output one array.
===========code php (adding)
$arrMy = $e["one"];
echo ""
===================
The console displays:
<
< illegal string offset 'one' in C:\test\test.php on line 17 >

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Karavaev, 2017-05-16
@JimmiJanger

The same code worked perfectly...
If this is just an abstract example, perhaps in real code you have a redefinition of this array, for example $e is used as an iterator in a loop.
foreach ($arrMy as $e => $item) {}

V
Vasily Pupkin, 2017-05-16
@HectorPrima

Didn't understand your code. Everything works:

$e1 = array(
  "t1" => 112,
  "t2" => 113);
$e2 = array(
  "s1" => 227,
  "s2" => 228);
$e = array(
  "one" => $e1,
  "two" => $e2);

$arrMy = $e["one"];

print_r($arrMy);

Result:
Array
(
    [t1] => 112
    [t2] => 113
)

M
Maxim Timofeev, 2017-05-16
@webinar

unexpected token

clearly speaks of a typo. Apparently the bracket is superfluous or missing. Put an editor with syntax highlighting, it will stupidly emphasize where the error is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question