Blogger Information
Blog 34
fans 1
comment 0
visits 23130
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP基础3作业08-23
theYon的博客
Original
627 people have browsed it

PHP基础3

主要知识点

1)初识数组

2)while语句的实战

代码

<?php


// while(),do~while()
$num1 = 1;
while( $num1 < 10 ){
    $num2 = 1;
    do {
        $temp = $num1 * $num2;
        echo $num2.'*'.$num1.'='.$temp.' ';
        $num2++;
    } while($num2 <= $num1);
    echo "<br>";
    $num1++;
}

// 函数的参数与作用域
$outsideMsg = '我是外部的信息';
function getMsg($varb='我是变量'){
    $insideMsg = '我是内部信息';
    return $varb.'----'.$insideMsg.'---'.$GLOBALS['outsideMsg'];
}

echo getMsg().'<br>';
echo getMsg('改变默认值').'<br>';
echo '<hr>';

// 数组常用的键值操作与指针操作
$arrBook = [
    'id' => 1001,
    'type' => 'book',
    'tag' => 'php',
    'name' => 'PHP基础入门',
    'price' => '20元'
];

echo '<pre>',var_export($arrBook),'<br>';

echo '输出值-',var_export(array_values($arrBook),true),'<br>';

echo '输出键-',var_export(array_keys($arrBook),true),'<br>';

echo "输出当前值",current($arrBook),'<br>';

echo "输出当前键",key($arrBook),'<br>';

next($arrBook);
echo "输出当前值",current($arrBook),'<br>';

echo "输出当前键",key($arrBook),'<br>';

var_export(each($arrBook));
echo '<hr>';
// reset($arrBook);
var_export(each($arrBook));
reset($arrBook);

// 数组模拟栈与队列操作
array_push($arrBook,'nums');
echo '<br>',var_export($arrBook);

array_shift($arrBook);
echo '<br>',var_export($arrBook);

array_unshift($arrBook, '新人');
echo '<br>',var_export($arrBook);

array_pop($arrBook);
echo '<br>',var_export($arrBook);

运行结果

TIM截图20180826171906.png

TIM截图20180826171916.png

TIM截图20180826171924.png

总结

    认识数组的基本操作以及对while语句的应用

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post