V
V
valvess2014-10-05 13:41:07
PHP
valvess, 2014-10-05 13:41:07

How to fix error with array?

The code

$mozg = preg_split("-[\W]-u", "1 2 3 4");
$go = $ilya = [];

for ($ali = 0; $ali <= count($mozg); $ali++) {
    for ($bobi = 0; $bobi < $ali; $bobi++) {
        $coomo = array(implode(' ', array_slice($mozg, $bobi, count($mozg) - $ali + 1)));

        if (!isset($ilya[$coomo])) {
            $ilya[$coomo] = array_push($go, $coomo);
        }
    }
}

print_r($go);

error appears in this function
if (!isset($ilya[$coomo])) {
            $ilya[$coomo] = array_push($go, $coomo);
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rostislav Grigoriev, 2014-10-05
@valvess

Because you are using an array as a key:

$coomo = [1,2,3];
$ilya = [];
$ilya[$coomo]  = 1; // this raised error

S
Sergey, 2014-10-05
Protko @Fesor

How to improve the for code? - Have you already started creating accounts for questions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question