How to convert a PHP array into a string

Source: Internet
Author: User
PHP Array into string [B] Array & nbsp; (& nbsp; [0] & nbsp; & gt; & nbsp; 0 & nbsp; [1] & nbsp; & gt; & nbsp; 1 [2] & gt; 1) how to convert an array into an array (, 1) or an array (a1, 0) [B] hope everyone can help ------ solution ------------------- convert the PHP array to a string
[B] Array ([0] => 0 [1] => 1 [2] => 1)How can this array be converted to array (, 1)
Or how to convert a =, 0 to array (, 0) [/B]
------ Solution ----------------------
Array ([0] => 0 [1] => 1 [2] => 1), that is, array (, 1), but it is printed out, the key name (subscript) is automatically added, which starts from 0 by default.
The second question is, do you want to do this?

$a='1,1,0';

$new=explode(',',$a);
echo "
";
print_r($new);
echo "
";
/*
Array
(
[0] => 1
[1] => 1
[2] => 0
)
*/


------ Solution ----------------------
PHP array conversion string
// Use The explode () function to convert a string to an array.
$ Str = "PHP, JSP, ASP"; // defines a string
$ Strs = explode (",", $ str); // Use The explode () function to convert a string to an array.
Print_r ($ strs); // output array element
?>
// Assign values directly to array elements
$ Array [1] = "";
$ Array [2] = "li ";
$ Array [3] = "ba ";
$ Array [4] = "ba ";
Print_r ($ array); // outputs the structure of the created array
?>

------ Solution ----------------------
Array_values ($ arr );
------ Solution ----------------------
String, 0 needs to be saved to the array by number and explode ()
If you need a method to store arrays with strings/files, use serialize () and unserialize ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.