1.demo1
2.demo2
实例
<?php $name = 'yiding'; $age = 18; $it = true; echo '年龄' . $age . '<br>'; echo '是否已婚: ' . $it . '<br>'; echo '姓名: ' . $name . '<br>'; echo '我的姓是: ' . $name{0} . '<br>'; print('年龄' . $age . '<br>'); echo print('年龄' . $age . '<br>'); echo '<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, $it);
运行实例 »
点击 "运行实例" 按钮查看在线实例
运行结果图:
3.demo3
实例
<?php $user[] = 11; $user[] = 'admin'; $user[] = 'a@qq.com'; $user = [11, 'admin', 'a@qq.com']; echo $user[2] . '<br>'; 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>'; while (list($key, $value) = each($user)) { echo '[' . $key . '] => ' . $value . '<br>'; } $user = ['id'=>11, 'name'=>'admin', 'email'=>'a@qq.com']; 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=test'; $username = 'root'; $password = 'root'; $linkParams = compact('dsn', 'username', 'password'); print_r($linkParams); echo '<br>'; print_r(array_values($user));
运行实例 »
点击 "运行实例" 按钮查看在线实例
运行结果图:
手写: