O
O
Oleg Rostovtsev2016-09-10 11:24:05
PHP
Oleg Rostovtsev, 2016-09-10 11:24:05

Assigning values ​​to arrays. How?

Interested in this question

function func() {
  $error = Array();
  return $error[] = 'Текст';
}
$a = fucn();

In this case, after returning the variable $a is assigned a string value.
In case you change
$error = Array();
$error[] = 'Текст';
return $error;

As expected, an array is obtained. Why is this happening??? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Kot, 2016-09-10
@oleshka25

In the second case, you return an array, and in the first case, the result of the variable assignment operation, and in php it will be the value itself, i.e. in this example a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question