How do you write variable initialization?

Source: Internet
Author: User
How do you write variable initialization? A small number of variables initialize. if the number is large, it will be a little uncomfortable. $ a, $ B, $ c, $ d, $ e ..... write $ a0; $ b0; $ c0; $ d0; $ e0 ;.... not easy to read, inconvenient, uncomfortable... so how do you initialize it? Don't tell me not to initialize. close the error prompt. ------ solution ------------------ $ a $ B $ c... 0; $ d $ Variable initialization how do you write?
A small number of variables
If the number is large, it will be a little uncomfortable.

$ A, $ B, $ c, $ d, $ e .....

Write it like this
$ A = 0;
$ B = 0;
$ C = 0;
$ D = 0;
$ E = 0;
....

Not easy to read, inconvenient, uncomfortable...

So how do you initialize it? Don't tell me not to initialize. close the error prompt.


------ Solution --------------------
$ A = $ B = $ c =... = 0;
$ D = $ e =... = array ();
So nice to see? Haha, I haven't met many variables that need initialization.
------ Solution --------------------
If there are no rules, then we can only be human. Write normally. If you can use extract/list from the array;
Reference section:
PHP code
$ My_array = array ("a" => "Cat", "B" => "Dog", "c" => "Horse"); extract ($ my_array ); echo "\ $ a = $ a; \ $ B = $ B; \ $ c = $ c"; // output: $ a = Cat; $ B = Dog; $ c = Horse
------ Solution --------------------
I won't design so many variables. haha. Just write a few lines honestly.
------ Solution --------------------
Php does not allow initialization of variables, which shows the flexibility and simplicity of php.
If initialization is required
Extract (array_flip (explode (',', 'a, B, c, d, e, f, g, h ')));

$ A = 0;
$ B = 0;
$ C = 0;
$ D = 0;
$ E = 0;
... Annoying !!

$ A = $ B = $ c =... = 0;
$ D = $ e =... = array (); also annoying !!

------ Solution --------------------
When php becomes a compiled language, you will not bother. What do you get bored ....
------ Solution --------------------
Not only do I have to write data in different rows, but also add comments to each line.
Why do we need to initialize so many variables in a report? Share your design.
I have also done a custom report function. I select a table, select a field, select an association, select a condition, add statistics, and add a filter search. it seems that there is no need to initialize multiple variables.
------ Solution --------------------
When php was designed, it was impossible to define variables when they were used. That guy corrected php to something similar to a strong type. Just like a hybrid. It's not easy. it's hard for php programmers.

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.