PHP Common utility Function _php Tutorial

Source: Internet
Author: User
1. For foreach in fact the $key=> $value and $i = $g is the same effect, and is not limited to key value

echo "
\ n ";

$arr = Array ("One", "one", "three");

foreach ($arr as $i = = $g) {

echo "Key: $i; Value: $g
\ n ";

}

?>

2. Array_fill () function

Fills an array with the given value

$a = Array_fill (5, 6, ' banana ');

Print_r ($a);

?>

Output:

Array ([5] = banana [6] = banana [7] = banana [8] = banana [9] = = Banana [ten] = banana)

3. Print Array (PHP mode and JSON mode)

$data = Array (

' FirstName ' = ' Tom ',

' LastName ' = ' Smith ',

' Age ' =>40

);

Print_r ($data);

echo Json_encode ($data);

Output:

Array ([FirstName] = Tom [LastName] = Smith [age] + 40)

{"FirstName": "Tom", "LastName": "Smith", "Age": 40}

4. Print_r ($data, true); So you can write the array into the log www.2cto.com

$a = Array ("A", "B", "C");
$c = Print_r ($a, true);

$logfile = "T.txt";

Error_log ("{$c}\r\n\r\n", 3, $logfile);

Excerpt from Hata Lishin's Crazy coding life

http://www.bkjia.com/PHPjc/478354.html www.bkjia.com true http://www.bkjia.com/PHPjc/478354.html techarticle 1. For foreach actually using $key= $value and $i = $g is the same effect, and is not limited to key value? PHP echo br/\n; $arr = Array (one, one, three); foreach ($a RR as $i = $g) {echo Key: ...

  • 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.