PHP beginners have doubts about how to solve the problem

Source: Internet
Author: User
Tags php for beginners
New PHP beginners are confused about what they have learned before. net and java & nbsp; at present, I have looked at PHP and found that PHP is not encapsulated much better than the previous two, it seems that ASP has looked at PHP and said above that PHP also has an object-oriented design pattern MVC and other frameworks. The following are some questions about PHP in the past few days! I'm grateful. 1. is there a wildcard array like List & lt; T & gt; in PHP? I have defined a Mode PHP for beginners.
I have studied. net and java before.

At present, I have looked at PHP and found that PHP seems to be poorly encapsulated than the previous two, and it feels like ASP

I looked at PHP and explained that PHP also has an object-oriented design pattern MVC and other frameworks.

The following are some questions about PHP in the past few days! Grateful

1. is there a List similar to that in PHP? What about generic arrays?

I have defined a Model (UserInfo)
When I query all the Userinfo result sets in the database, how can I get the result and it is not displayed again?

2. how to separate WEB and PHP code in PHP?
For example, what is the difference between servlet and jsp pages in java?

------ Solution --------------------
1,
$ M = M ('userinfo ');
$ List = $ m-> select ();
/*
$ This-> assign (... $ list );
$ This-> display;
*/
Print_r ($ list );

2. replace the template, that is, the assign in 1, is to replace the $ list variable with the corresponding location in the pre-written Template File. This template is generally the same as the current controller, in the Tpl directory.


MVC... you have to use MVC like JAVA. it is really unnecessary in PHP. in PHP, I personally feel that MVC is more of a programming design concept, and many frameworks are written by fans, isn't it just layering? everyone will, but why do we follow the rules of a framework? PHP should be simple enough and agile enough. The framework is a personal habit and easy to use, it can be said that it is too simple.

------ Solution --------------------
1: Array
2: call the class method after instantiation.
3: smarty/custom template
------ Solution --------------------
The answer is brilliant.
Discussion

1: Array
2: call the class method after instantiation.
3: smarty/custom template

------ Solution --------------------
PHP Manual
PHP code
#1: $ result = mysql_query ("SELECT id, name, salary FROM employees", $ conn); while (list ($ id, $ name, $ salary) = mysql_fetch_row ($ result) {echo"\ N "."$ Name\ N "."$ Salary\ N "."\ N ";}# generally, the result set of the loop is put into an array and called on the page to facilitate reading the code. this involves the second problem: # php code: $ result = mysql_query ("SELECT id, name, salary FROM employees", $ conn); $ arr = array (); while ($ rows = mysql_fetch_array ($ result, MYSQL_ASSOC )) {array_push ($ arr, $ rows) ;}# html code:
   
   
  
ID
Name

------ Solution --------------------
The above experts have answered some questions from different perspectives,
Let me talk about it again,

0. php is indeed inferior. net/java encapsulation. because php is a gradient language, from the process to OO, it is also an open-source language for cooperative development. different authors will bring different styles to it, at the same time, compatibility is also important because of the popularity. not like. net.

1. php has an array which can be used as a list. other containers are also provided in spl.
However, php does not have a generic concept, because php is a dynamic type.

2. Template. participate in answers from upstairs



Discussion
I have studied. net and java before.

At present, I have looked at PHP and found that PHP seems to be poorly encapsulated than the previous two, and it feels like ASP

I looked at PHP and explained that PHP also has an object-oriented design pattern MVC and other frameworks.

The following are some questions about PHP in the past few days! Grateful

1. is there a List similar to that in PHP? What about generic arrays?

I have defined a Model (UserInfo)
When I query the database ......

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.