Home > Backend Development > PHP Tutorial > 我教PHP(一)

我教PHP(一)

WBOY
Release: 2016-06-23 14:36:46
Original
923 people have browsed it

公司来了个新人,号称写过8个月PHP,然后会写mysql_connect,不会写循环,不理解二维数组等。基础差的让我想一头撞死。

唉,教一教吧,看能不能教出来。

-----------------------------------------------------------
PHP的变量最主要有3种。string , array , object
怎么使用它们呢。

-----------------------------------------------------------
对于String
$string = "字符串"
-----------------------------------------------------------
建个test.php,测试下面的例子,看看输出结果有什么不同,有什么相同的

 $str = "我是字符串";
 echo $str;
 $str2 = "他是数组,我是字符串2";
 echo $str2;


-----------------------------------------------------------
对于Array
$arr = array( 'key'=>'value' );
-----------------------------------------------------------
建个test.php,测试下面的例子,看看输出结果有什么不同,有什么相同的

$arr = array( 'name'=>'张三' , 'php'=>'初学' );
print_R($arr)

$arr2['name'] = '张三';
$arr2['php']  = '初学';
$arr2['info']  = 'HTML熟练';
print_R($arr2)


-----------------------------------------------------------
对于Object
$ob = new stdClass;
$ob->key = value;
-----------------------------------------------------------
建个test.php,测试下面的例子,看看输出结果有什么不同,有什么相同的

$ob = new stdClass;
$ob->name = '张三';
$ob->php = '初学';
print_R($ob)

$ob2 = new stdClass;
$ob2->name = '张三';
$ob2->php = '初学';
$ob2->info = '还不错';
print_R($ob2)

 

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template