D
D
Dmitry Petrik2014-09-20 00:24:07
Yii
Dmitry Petrik, 2014-09-20 00:24:07

PHP. Yii. How to make one multidimensional array for two one-dimensional arrays?

There are two arrays

array('0'=>'x', '1'=>'xx', '2'=>'xxx', '3'=>'xxxx',)

and
array('0'=>'y', '1'=>'yy', '2'=>'yyy', '3'=>'yyyy',)

How to make an array of the form:
array(
array('0'=>'x', '1'=>'xx', '2'=>'xxx', '3'=>'xxxx',),
array('0'=>'y', '1'=>'yy', '2'=>'yyy', '3'=>'yyyy',),
)

UPD:
All this is written in Yii. Controller:
$cars=AutoCars::model()->findAll();
$allCars=array();
foreach ($cars as $car) {
         $deCar=CJSON::decode($car->params, true);
         $allCars[]=$deCar; //на этом месте исключение
}

An exception is thrown:
htmlspecialchars() expects parameter 1 to be string, array given

It’s clear why the error is, but it’s not clear what place htmlspecialchars() got in here? And how do you make sure everyone is happy?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Twist, 2014-09-20
@bboytiwst

<?

$a = array();

$b = array("c" => "2");

$c = array("d" => "3");

$a[] = $b;
$a[] = $c;

the first thing that came to my mind) I'm sure that you can also merge with standard functions (array_push etc)
I didn’t work very tightly with yii (for which I am very glad): D
www.yiiframework.com/doc/api/1.1/CJSON
Uses json_decode / json_encode if they are, and accordingly a string is required for input, because if you pass an array, then there will be an error.
$car->params - an array, but it must be a string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question