Implode does not work for me PHP

0
if( count($usuario['info']['cv']['habilidad']) > 0 && isset($usuario['info']['cv']['habilidad']) && $usuario['info']['cv']['habilidad']){
    $html .= '<div style="font-size: 16px; border-bottom: 1px solid #999999; color: #F29222; font-weight: normal;"><img src="img/curriculum-04.png" width="20" align="middle"> Habilidades</div>';
    $html .= '<div>'.implode(", ", $usuario['info']['cv']['habilidad']).'</div>';
}

Error:

Warning: count(): Parameter must be an array or an object that implements Countable in /main.php on line 1438
TCPDF ERROR: Some data has already been output, can't send PDF file

var_dump :
array(2) { [0]=> array(5) { ["id"]=> int(212) ["habilidad"]=> int(7) ["usuario"]=> int(5000) ["documento"]=> string(0) "" ["otro"]=> string(0) "" } [1]=> array(5) { ["id"]=> int(213) ["habilidad"]=> int(2) ["usuario"]=> int(5000) ["documento"]=> string(0) "" ["otro"]=> string(0) "" }}
    
asked by DoubleM 05.12.2018 в 00:29
source

1 answer

0

The error (at least the one that marks you) is the count, not the implode. Another thing is that in addition (to root or not) of that count, you are giving another problem in the implode.

However, before checking if the count is greater than zero, you should check first if the array / object exists, otherwise, if it does not exist, it will also give you an error because it will try to count the elements or properties of something that is not defined. That is:

Instead of doing this:

...count($usuario['info']['cv']['habilidad']) > 0 && isset($usuario['info']['cv']['habilidad'])...

you should do this:

...isset($usuario['info']['cv']['habilidad']) && count($usuario['info']['cv']['habilidad']) > 0...

Apart from this, try doing a var_dump on the variable so that you can see exactly what it has.

var_dump($usuario['info']['cv']['habilidad']);

UPDATE

Okay, well, I think we already have it. What I think is happening to you is that your array is composed of elements that are arrays, not strings / ints / etc ... and what the implode function expects is that you pass an array whose elements are strings / ints / etc ..

That is:

$a = array('a','b','c','d');
echo implode('|',$a) //sacará por pantalla a|b|c|d

But in your case you have something like:

$a = array(array(5),array(5));

that's why when you are going to "unite" both elements of the main array, you find more arrays and that "can not join" and give it as good, and that's why you let go of the warning. Basically it is saying to you: "I have united it, but be careful because what I have joined are arrays".

Probably what you are looking for is an implode of each one of the values of those internal arrays. As I'm not sure what you want to get out of the screen, could you give me a simple example of what you hope to get please?

    
answered by 05.12.2018 в 00:43