<?php
$site = 'php.cn';
function get_site($webSite)
{
return $webSite . ' 欢迎您';
}
echo get_site($site);
<?php
// 变量名是name, 变量值的类型是字符串
$name = 'Peter Zhu';
$age = 30;
$isMarried = true;
echo '年龄' . $age . '<br>';
echo '是否已婚: ' . $isMarried . '<br>';
echo '姓名: ' . $name . '<br>';
echo '我的姓是: ' . $name{0} . '<br>';
print('年龄' . $age . '<br>');
echo print('年龄' . $age . '<br>');
print_r($name);
echo '<br>';
echo print_r($name, true);
$data = range(1,20,2);
echo '<pre>'. print_r($data, true) . '</pre>';
var_export($name);
echo '<br>';
var_dump($name, $age, $isMarried);
<?php
// (一)索引数组
$user[] = 101;
$user[] = 'admin';
$user[] = 'admin@php.cn';
$user = [101, 'admin', 'admin@php.cn'];
echo $user[2] . '<br>'; // email
print_r($user);
echo '<pre>' . print_r($user, true) . '</pre>';
var_dump($user);
echo '<hr>';
$res = '';
for ($i = 0; $i < count($user); $i++) {
$res .= $user[$i] . ', ';
}
echo rtrim($res, ', ');
echo '<hr>';
$res = '';
foreach ($user as $item) {
$res .= $item . ', ';
}
echo rtrim($res, ', ');
echo '<hr>';
list($id, $name, $email) = $user;
echo $id . '--' . $name . '--' . $email . '<br>';
$str = implode(',', $user);
echo $str, '<br>';
$sql = "INSERT `users` SET `comment` = {$str};";
$arr = explode(',', $str);
print_r($arr);
echo '<br>';
/****************************************************************/
// (二) 关联数组
$user = ['id'=>101, 'name'=>'admin', 'email'=>'admin@php.cn'];
echo $user['email'] . '<br>';
print_r($user);
var_dump($user);
var_export($user);
echo '<hr>';
foreach ($user as $key=>$value) {
echo '[' . $key . '] => ' . $value . '<br>';
}
$res = '';
for ($i = 0; $i < count($user); $i++) {
$res .= current($user) . ', ';
next($user);
}
echo rtrim($res, ', ');
echo '<hr>';
extract($user);
echo 'id = ' . $id . ', name = ' . $name . ', email = ' . $email . '<br>';
$dsn = 'mysql:host=localhost;dbname=demo';
$username = 'root';
$password = 'root';
$linkParams = compact('dsn', 'username', 'password');
echo '<pre>'. print_r($linkParams, true) . '</pre>';
echo '<hr>';
return
print_r(array_values($user));
echo '<hr>';
$chai = implode(',',$user);
echo $chai, '<br>';
$sql = "INSERT `users` SET `comment` = {$chai};";
// echo exit;
$arr = explode(',', $chai);
print_r($arr);
echo '<br>';
手抄
总结:通过部分梳理,发现一些漏掉的知识点,补足一些不太明白的知识点!努力!