php问题,高人进来看看

来源:百度知道 编辑:UC知道 时间:2024/06/04 17:06:32
小弟初入php 身在国外。明天要交作业了。啥都不懂。。希望大虾们帮忙解决下。
<!-- Do NOT modify the provided skeleton; just add your code to it-->

<html>
<head> <title>Task 1a (Tute 3-4) </title></head>
<?php
function unique($s_arr) {
$us_arr = array();
foreach ($s_arr as $s) {
foreach ($us_arr as $us) {
//这里加代码,2行只要(2 lines needed)
}
return $us_arr;
}
?>

<body>
<?php
$str = array(42, 24, 2, 4, 42, 24, 2, 4, 24, 42, 42, 24);
//$str = array("hi","hi","ho","hi","ho","ho");
$uStr = unique($str);

//(这里加代码,只需要2行)add code here so that the content of $uStr is printed out (2 lines needed)

?>
</body>
</html>

保证结果是
42
24
2
4

然后改动一点点用array
eg $str = array('Mon'=>'1', 'Tue'=

<?php
function unique($s_arr) {
$us_arr = array();
foreach ($s_arr as $s) {
if(!in_array($s,$us_arr))
array_push($us_arr,$s);
}
return $us_arr;
}

$str = array(42, 24, 2, 4, 42, 24, 2, 4, 24, 42, 42, 24);
//$str = array("hi","hi","ho","hi","ho","ho");
$uStr = unique($str);
foreach($uStr as $value)
echo $value,'<br>';
?>
这样就可以了