A
A
Arseny Sokolov2015-09-24 15:32:30
PHP
Arseny Sokolov, 2015-09-24 15:32:30

How to do it correctly so that when splitting a string into an array, build a cycle inside that would meet certain requirements?

Let's say there is a string that we split into an array and check the size of the array, so that we can then use this array to form a multidimensional array:

$_str = 'key01$key02';
$_arr = implode('$', $_str);
$_line = array();
if (count($_arr) > 1) {
    $_line[] = $_data[$_arr[0]][$_arr[1]];
}

How to make it so that you do not manually write $_arr[0], $_arr[1], $_arr[n] , because the $_data array itself can contain multiple attachments.
PS
Help me to ask a question correctly, otherwise, like a freak, I can’t formulate my question briefly, some kind of mess in my head ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lyeskin, 2015-09-24
@ArsenBespalov

$_str = 'key01$key02';
$_arr = implode('$', $_str);
$_line = array();
if (count($_arr) > 1) {
    $tmp_arr = array();
    foreach($_arr as $key){
       $tmp_arr = is_empty($tmp_arr) ? $_data[$key] : $tmp_arr[$key];
    }
    $_line[] = $tmp_arr;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question