PHP Day 2

echo has no return value while print has a return value of 1 so it can be used in expressions.

echo can take multiple parameters (although such usage is rare) while print can take one argument.


strlen() function returns the length of a string.

str_word_count() function counts the number of words in a string

strpos() function searches for a specific text within a string.

str_replace() function replaces some characters with some other characters in a string.


To create a constant, use the define() function.

define(name, value, case-insensitive)

Constants are automatically global and can be used across the entire script.


+ is Addition / Array Union

. is String Concatenation


foreach Loop

foreach ($array as $value) {
    code to be executed;
}


PHP Default Argument Value

function setHeight($minheight = 50) {
    echo "The height is : $minheight <br>";
}


In PHP, there are three types of arrays:
Indexed arrays - Arrays with a numeric index
Associative arrays - Arrays with named keys

Multidimensional arrays - Arrays containing one or more arrays

Associative arrays are arrays that use named keys that you assign to them.

There are two ways to create an associative array:

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

or:

$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";


Superglobals

$GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods).

$_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.

$_REQUEST is used to collect data after submitting an HTML form.

$_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.

$_GET can also be used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值