想知道是否有可能像func_get_args()(引用)那样进行调用而不是产生0索引数组,导致关联数组,使用变量名作为键?
例如:
function foo($arg1, $arg2)
{
var_dump(func_get_args());
}
foo('bar1', 'bar2');
// Output
array(2) {
[0]=>
string(4) "bar1"
[1]=>
string(4) "bar2"
}
// Preferred
array(2) {
[arg1]=>
string(4) "bar1"
[arg2]=>
string(4) "bar2"
}
Run Code Online (Sandbox Code Playgroud)
我问的原因是,我需要验证这些args作为数组传递给RPC函数,实际上是填充的.而且似乎最好是具体内容而不是希望它们以正确的顺序传递:
// Now
if (array_key_exists(0, $args)) {
// Preferred
if (array_key_exists('arg1', $args)) {
Run Code Online (Sandbox Code Playgroud)
在传递给RPC之前,我很容易从传入原始函数的args创建一个assoc数组,但只是想知道是否有一个已编译的函数为我做这个.
谢谢.
- 编辑 -
对不起,我忘了提到我触摸的代码已经存在,这意味着我无法更改功能签名.
给出以下select语句:
Select t.name, SUM(st.row_count) as row_count
From sys.dm_db_partition_stats st
join sys.tables t on t.object_id = st.object_id
join ClientUpdateConfig c on t.name = c.TableName
Where (index_id < 2) and schema_id = schema_id('dbo')
and t.type ='U'
group by t.name
Run Code Online (Sandbox Code Playgroud)
我还想选择c.RowID作为附加字段.查询按原样运行,但如果我像1那样更改为:
Select t.name, SUM(st.row_count) as row_count, c.RowID as current_row
Run Code Online (Sandbox Code Playgroud)
我收到错误:
消息8120,级别16,状态1,行1列"ClientUpdateConfig.RowID"在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中.
有人可以解释为什么我需要聚合函数中的选择值(我假设是SUM)或者在group by中选择它吗?我不明白这个限制 - 如果我能理解为什么会这样,我可以调整我的查询设计.
通过setcookie()和设置cookie之间有什么区别$_COOKIE吗?
有时,当设置cookie时setcookie,我没有通过$ _COOKIE ['cookie_name']获得该cookie的值.但是js console.log之后立即setcookie显示cookie已设置但是如果我试图获取该值的值cookie通过$ _COOKIE,我没有得到更新的值.
我糊涂了..!!
我在回滚涉及多个数据库中的表的事务时遇到问题。主表回滚的行为符合预期,但子行仍然存在,并且现在是孤立的。
public function devUserCreateTest()
{
DB::beginTransaction();
try {
$childUser = new ChildUser; // Exists in database B
$parentUser = new User; // Exists in database A
$parentUser->setEmailAttribute('mike@yourmomshouse.com');
$parentUser->save();
$childUser->parent_user_id = $parentUser->id;
$message = sprintf('Parent user id: %s', serialize($childUser->id));
$childUser->save();
$message = sprintf('Core user id: %s | hta user id: %s', serialize($parentUser->id), serialize($childUser->id));
throw new Exception('Testing....');
DB::commit();
} catch (Exception $e) {
Log::warning(sprintf('Exception: %s', $e->getMessage()));
DB::rollback();
}
return $this->buildResponse(array('message' => $message));
}
Run Code Online (Sandbox Code Playgroud)
看起来这样有效:
public function devUserCreateTest()
{
$dboA = DB::connection();
$dboB …Run Code Online (Sandbox Code Playgroud) 我稍微简化了WAMP提供的默认index.php文件,因此它可以在任何目录/位置工作.
我遇到的问题是订单是将资本分组在一起.
例如a,b,c,A,B,C
当我想要:A,a,B,b,C,c
<?php
date_default_timezone_set('Europe/London');
$title = 'Project Directory';
$server = 'http://' . $_SERVER['SERVER_NAME'];
$date = date('Y');
//Directory / Files
$dir = '.';
$files = scandir($dir);
$projectsListIgnore = array ('RemoteSystemsTempFiles','icons');
$projectsFileListIgnore = array ('.project');
$projectContents = '';
$projectFileContents = '';
foreach ($files as $file) {
if (is_dir($file) && !in_array($file,$projectsListIgnore) && substr($file,0,1) != '_' && substr($file,0,1) != '.') {
$projectContents .= '<li><a class="arrow external" href="'.$file.'">'.$file.'</a></li>';
}
if (is_file($file) && !in_array($file,$projectsFileListIgnore) && substr($file,0,1) != '_' && substr($file,0,1) != '.') {
$projectFileContents …Run Code Online (Sandbox Code Playgroud) 好吧,我开始拉我的头发,我需要一些帮助:)
这是我的文件,用于选择用户激活的电子邮件并向他们发送某种新闻通讯.
newsletter.php的内容
<?php
//Include configuration file
include 'config/config.php';
$pdo = new PDO("mysql:host=localhost;dbname=$db", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Define messages
//Error messages
define('ERROR_MESSAGE_SUBJECT', 'Enter subject');
define('ERROR_MESSAGE_CONTENT', 'Enter some content');
//Define variables
$errorFlag = false;
$to = array();
//Grab variables
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$newsletterSubject = check_input($_POST['newsletterSubject']);
$newsletterContent = $_POST['newsletterContent'];
if(!$newsletterSubject) {
$errorSubject = ERROR_MESSAGE_SUBJECT;
$errorFlag = true;
}
if(!$newsletterContent) {
$errorContent = ERROR_MESSAGE_CONTENT;
$errorFlag = true;
}
}
?>
<form action="newsletter.php" method="post">
<label>Naslov newsletter-a: <?php echo '<span class="error">'.$errorSubject.'</span>';?></label>
<input type="text" …Run Code Online (Sandbox Code Playgroud)