Home > Backend Development > PHP Tutorial > 这个函数怎么写??

这个函数怎么写??

WBOY
Release: 2016-06-23 14:39:38
Original
856 people have browsed it

本帖最后由 u013177281 于 2013-12-16 20:03:59 编辑

<?php$guanggaotutiao1=$_MODULE["guanggaotiao1"];if($guanggaotutiao1){	$bjjs='background:url('.$guanggaotutiao1.')';		}else{	$bjjs='';	}?>
Copy after login


输入函数参数guanggaotiao1 出现上面的效果 的函数

$guanggaotutiao1是全局哦

这个函数怎么写??


回复讨论(解决方案)

$guanggaotutiao1=$_MODULE["guanggaotiao1"];function guangGao($url){	if($guanggaotutiao1){    	$bjjs='background:url('.$guanggaotutiao1.')';      	}else{    	$bjjs='';	}	return $bjjs;}guanGao($guanggaotutiao1);
Copy after login
Copy after login
Copy after login

$guanggaotutiao1=$_MODULE["guanggaotiao1"];function guangGao($url){	if($guanggaotutiao1){    	$bjjs='background:url('.$guanggaotutiao1.')';      	}else{    	$bjjs='';	}	return $bjjs;}guanGao($guanggaotutiao1);
Copy after login
Copy after login
Copy after login
不对啊 $guanggaotutiao1这个会变得


$guanggaotutiao1=$_MODULE["guanggaotiao1"];function guangGao($url){	if($guanggaotutiao1){    	$bjjs='background:url('.$guanggaotutiao1.')';      	}else{    	$bjjs='';	}	return $bjjs;}guanGao($guanggaotutiao1);
Copy after login
Copy after login
Copy after login
不对啊 $guanggaotutiao1这个会变得
$guanggaotutiao1=$_MODULE["guanggaotiao1"];这个不就是获取变化的$guanggaotutiao1吗?
然后再调用 guangGao();这个函数呀!

<?phpfunction guangao(){    global $guanggaotutiao1;    if($guanggaotutiao1)    {	$bjjs='background:url('.$guanggaotutiao1.')';    }    else    {	$bjjs='';    }    return $bjjs;}?>
Copy after login

无需函数
$bjjs = $_MODULE["guanggaotiao1"] ? 'background:url('.$_MODULE["guanggaotiao1"].')' : '';

一定要写成函数的话
function background($url) {
  return $url ? "background:url($url)" : '';
}
调用
$bjjs = background($_MODULE["guanggaotiao1"]);

?帖率是0,我去

结帖率0的就没必要搭理了,最起码的尊重都不知道

警告楼上两位!不要做人身攻击
楼主的 注册日期:2013年12月16日
才发此一贴,自然结帖率为0

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template