PHP中的基本数组

时间:2016-02-09 16:25:50

标签: php arrays

我想将偶数添加到数组然后回显它,这是我的代码,但是当我打印时它只显示array()...我做错了什么?

<script> 
 x= get date
 if (date  <= showbefore & >= showafter){show div}
<html>
<div 1 showbefore = a showafter = b> !-- advert for valentines
<div 1 showbefore = a showafter = c> !-- advert for mothers day
<div 1 showbefore = d showafter = f> !-- advert for easter sunday
<div 1 showbefore = h showafter = x> !-- advert for christmas. 

1 个答案:

答案 0 :(得分:3)

您应该从while循环移动“均匀度”测试,并将其移至while循环中的条件:

<?php
    $x = 88;
    $numbers = array();
    while ($x <= 99) {
        if ($x % 2 == 0) {
            $numbers[] = $x;
        }
        $x++;
    }
    print_r($numbers);
?>

正如您当前编写的while循环一样,如果数字不均匀则结束。您还应该在添加到$x数组时从$numbers删除引号。