PHP简单练习代码

时间:2023-02-13 14:20:54


<?php


/**
 * @author Steve Smith
 * @copyright 2014
 */


$str="5";
echo $str;


$myTest='我的名字';
echo $myTest;


define("GREETING","Hello world!");
print constant("GREETING");


$txt1="Hello World";
$txt2="1234";
echo $txt1 . " "." " . $txt2;


echo strlen("Hello world!");


$expression ='10test';


switch ($expression)
{
case '10test1':
echo 'right';
  break;  


case 5:
echo 'wrong';
  break;
  
default:
    echo 'null';
    break;
}


$ages['Peter'] = "32test1";
$ages['Quagmire'] = "30test2";
$ages['Joe'] = "34test3";


echo $ages['Peter'];
echo $ages['Quagmire'];
echo $ages['Joe'];


echo $ages['Peter'];
echo $ages['Quagmire'];
echo $ages['Joe'];


echo $ages['Peter'];
echo $ages['Quagmire'];
echo $ages['Joe'];




if( in_array('32test1')){
    echo '包含数据';
}
else{


    echo '不包含数据';    
}


//判断是否存在某个字符串在数组中
$myArray=array(1,2,3,4,5,6,7,8);


if(in_array(23,$myArray)){
    echo "正确";
    }
    else
    {
        echo "错误";
    }


    echo "<br/>";
    
    
    for ($i=1; $i<=5; $i++)
{
  echo "Hello World!<br />";
}
    
    


?>