所以我有这个代码,它的一部分是一个表单,所有字段都是绝对必需的.
我只是找不到明确的文档来满足我验证所有内容的需求.
我会做这样的事吗?
$foo = $_POST['foo'];
$bar = $_POST['bar'];
$lorem = $_POST['lorem'];
$ipsum = $_POST['ipsum'];
$isSet = array($foo, $bar, $lorem, $ipsum);
if(isset($isSet)) { /* Do the stuff */ }
Run Code Online (Sandbox Code Playgroud)
或者,还有更好的方法?我真的不想这样做
if(isset($foo) && isset($bar) && isset($lorem)........
Run Code Online (Sandbox Code Playgroud)
因为我有大约12个领域是必需的
你能在"数组"函数中有一个"if"语句吗?
$my_array = array(
'foo' => $foo,
'bar' => 'bar',
'lorem' => $lorem,
if($z == 'z'){ 'ipsum' => $ipsum }
);
Run Code Online (Sandbox Code Playgroud)
我的问题当然属于第5行,数组中的第4项.它似乎不想工作,是否有一种方法可以做到这一点?
我有点坚持这个,它应该很简单,但我的大脑不能缠绕它(它是周五......哈哈)
我有一个温度计,代表最高1,000,000美元.它高375像素.
我正在运行数据库查询以从用户提交中获取金额(介于$ 1和$ 200之间).
在那个数学上,每像素的价格为2,666.66美元,将其向上移动1个像素---
retrieve_amount(); 是我的数据库功能,它可以获取所有金额 - 这很简单.
$fill_query = retrieve_amount();
$fill = 0;
$total = 0;
while($fill_query->is_valid() ) : $fill_query->amount();
$amount = get_valid_amount($input, 'amount');
$total = $total + $amount;
endwhile;
$finaltotal = $total; // THIS is the line that grabs the final total from above. Should work?
$fillheight = $SOMETHING +/-* $SOMETHING; // this is the line that i'm less sure of how to get my result
Run Code Online (Sandbox Code Playgroud)
可能我对数学不太满意,但我的问题是
$finaltotal = $total
Run Code Online (Sandbox Code Playgroud)
应该工作来接收从数据库查询中检索到的总金额,对吗?
更重要的是,我如何将其转换为我需要的像素?
我真的不明白这个API应该如何工作,因为我之前从未使用过JSON.
该文档没有给出任何示例,但它表示此API中的端点支持POST和GET操作,返回JSON.
我的问题是,我不确定如何实现这一点,假设我只是想把所有数据都放到一个简单的页面中,例如:
城市: 塞勒姆
邮编: 97302
等等...
我不太清楚从哪里开始:
POST http:// [您的RepMan主机名] /api/v1/account/reputation/current.json
获取http:// [您的RepMan主机名] /api/v1/account/reputation/current.json
以下是POST正文或GET查询字符串的参数列表.应按照普通的POST正文或GET查询字符串对所有值进行正确编码.
| Field | Ordinality | Datatype | Description
| pid | 1 | string | This is your partner ID as provided by us to access the API.
| apiKey | 1 | string | This is your API Key as provided by use to access the API.
| srid | ? | string | This is the unique RepMan ID for the …Run Code Online (Sandbox Code Playgroud) 我需要通过JSON从我的网站访问其他地方的一些变量.
始终定义所有选项.我的问题是,创建一个人造json或使用它是否更好json_encode.仿json看起来像这样:
{
"data": [
{
"optA": "<?php echo($optA); ?>",
"optB": "<?php echo($optB); ?>",
"optC": "<?php echo($optC); ?>"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我觉得'喜欢嵌套数组并使用json_ecode添加另一步.虽然,我知道一行一行的回声也增加了一些重量.
我倾向于使用,json_encode因为它被广泛使用.我的阵列也不会过于复杂,但绝对比上面的例子更加复杂.
可能重复:
参考 - 这个符号在PHP中意味着什么?
我似乎找不到两者之间的差异的答案
somephp" + foo + "morephp
Run Code Online (Sandbox Code Playgroud)
和
somephp" . foo . "morephp
Run Code Online (Sandbox Code Playgroud)
Dreamweaver认为两者在语法上都是正确的.我只需要一篇文章链接或解释作为它们之间的区别?谢谢!:)
我的具体情况是我有 - CHILD_POS - 需要插入静态字符串.基本上......:
echo 'some stuff goes here' +/. CHILD_POS +/. 'some more stuff goes here';
Run Code Online (Sandbox Code Playgroud)
我不确定是否使用(+)或(.)
我非常精通PHP,在OOP之外 - 我现在才开始跳槽.
我一直在看视频和阅读教程,但它们仍然令人困惑......
如果我有
文件1(class.time.php)
class Time {
function GetTime(){
$time = date('H:i:s');
printf($time);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在另一个php页面中我有了
文件2(page.php)
我可以
include('class.time.php');
Run Code Online (Sandbox Code Playgroud)
然后我可以在这个页面的任何地方做
$time = new Time; //Calling the class and setting the class to a variable
$time->GetTime(); //This is BASICALLY saying (run the 'GetTime' function in the 'Time Class'
Run Code Online (Sandbox Code Playgroud)
我的主要问题是,上面的评论(这是基本上说.....)正确吗?还是有更好的方法来思考它?