Is it possible to check the size of a string that is inside an array?

Asked

Viewed 483 times

2

I have a array which is built on the results of chekbox selected...

He returns with a var_dump:

array(3) { [0]=> string(7) "BXT0022" [1]=> string(7) "BXT0010" [2]=> string(7) "BXT0024" }

I just want to chekar if there’s anything on array or if it is empty, but I’m not succeeding because if there is nothing selected it returns this:

string(0) ""

How can I do an if (has nothing on array) makes the implode... I tried with the count of array but always gives 1 even with nothing chosen , issset there’s something there too and it doesn’t work... I don’t know what else to use...

It’s kind of chekar the length of the string array returns?

4 answers

2

Use empty:

if(empty($variavel)) { ...

He returns true for both empty strings and empty arrays.

  • Thanks is what I need ...thank you very much

  • @user7385, mark this answer as accepted.

  • You mean, "he returns true", right?

  • @mgibsonbr Ops, this

1

When using implode in an empty array will give 1 because the array starts at position 0 then vc has q decrease 1 of the variable q counts the size of the array

0

if(strlen($variavel) > 0)

It will check how many characters the string has passed, if it is greater than 0, it is because it has something

But it can be used several times:

if(!isset($variavel))
if($variavel != "")
if($variavel != NULL)
if($variavel[1]) - uma string pode ser usada como array sem ter que fazer ela ser um array

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.