Check if there is a value of an array element

0

Well, I've put the following code to read array :

    for ($i_p = 1; $i_p < $array; $i_p++) {

        // Pega nome e valos da variavel
        $array_v_p = explode("=", $array_p[$i_p]);

        // Verifica se existe valor para montar variáveis
        if (empty($array_v_p[0]) !== (string) null) {

            if (empty($array_v_p[1]) !== (string) null) {
                $variavel = $array_v_p[1];
            } else {
                $variavel = null;
            }

            $$array_v_p[0] = "$array_v_p[1]";
        }
    }

The following error is displayed:

  

PHP Notice: Undefined offset: 1 in index.php on line 8

This is the line that has the error:

if (empty($array_v_p[1]) !== (string) null) {

Does anyone know how to handle this error?

    
asked by anonymous 20.10.2016 / 18:44

1 answer

1

Switch:

if (empty($array_v_p[1]) !== (string) null)

By:

if ( isset($array_v_p[1]) and !empty($array_v_p[1]) )

That is, if the element exists AND if it is not empty.

    
20.10.2016 / 18:54