0
How to concatinate square bracket to text only if array is not empty
Hallo, I have an Array that is soetimes empty and sometime have lalues. After extraction I want the answer to be in square bracket. So how to add those only if the Array habe Elements? If I use this: $a . "[ " , $b ."]". It is ok if the Array have Elements, but if the Array is emoty i get this Output: [] Please help https://code.sololearn.com/wn12f6tlvmFr/#php
2 Respostas
+ 3
You may test if your result is empty... as you do your code, the simplest is to change the last expression:
$final = $z . ($b ? " [" . $b . "]" : "");
that's a ternary operator (an if-else shortcut) wich say to concat to $z an empty string if $b is empty, else concat $b wrapped in square brackets.
0
visph thank you! it works like charm!!!