问题描述:

$string_to_split = (1_house & flats);

$split_string = explode("_", $string_to_split);

As shown above I'm trying to split a string into an array

When I print $split_string[0] I get 1 of which it's correct according to my expectations but when I print $split_string[1] I get "house" not "house & flats"because that's what I expected.

网友答案:

I will suggest you put your String_to_split in quotes like "1_house and flats". Do not make use of the brackets to indicate a string.

Since your string is not in quotes, Php sees the & sign as an operator, that's why it won't give you the "house and flats", as you require.

Your syntax for the explode Function is OK. Wish you success.

相关阅读:
Top