如何将字符串数组转换为整数数组?
我当前的 PHP 代码遇到此错误:
注意:TO id 不是整数:1, 2。 1) APNS::queueMessage ->
如何将字符串数组转换为整数数组,就像另一个问题一样: ID 不是整数。 .. EasyAPNS ?
我基本上试图将 id
(从我的数据库)传递给 newMessage()
,就像这个苹果示例:
// SEND MESSAGE TO MORE THAN ONE USER
// $apns->newMessage(array(1,3,4,5,8,15,16));
// ($destination contain a string with the Ids like "1,2,3")
下面是我的代码:
if (isset($destination))
{
//$destination = 1,2,..
$dest = explode(",", $destination);
if (isset($time))
{
$apns->newMessage($dest, $time);
}
else
{
$apns->newMessage($dest);
}
$apns->addMessageAlert($message);
$apns->addMessageBadge($badge);
$apns->addMessageSound('bingbong.aiff');
$apns->queueMessage();
header("location:$url/index.php?success=1");
}
I'm getting this error with my current PHP code:
Notice: TO id was not an integer: 1, 2. 1) APNS::queueMessage ->
How can I convert to an array of strings to an array of integers like in this other question: ID not integer... EasyAPNS ?
I'm basically trying to pass id
s (from my database,) to newMessage()
like this Apple example:
// SEND MESSAGE TO MORE THAN ONE USER
// $apns->newMessage(array(1,3,4,5,8,15,16));
// ($destination contain a string with the Ids like "1,2,3")
Here is my code below:
if (isset($destination))
{
//$destination = 1,2,..
$dest = explode(",", $destination);
if (isset($time))
{
$apns->newMessage($dest, $time);
}
else
{
$apns->newMessage($dest);
}
$apns->addMessageAlert($message);
$apns->addMessageBadge($badge);
$apns->addMessageSound('bingbong.aiff');
$apns->queueMessage();
header("location:$url/index.php?success=1");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将创建一个接受数组的包装函数,然后调用它。
这样,您可以使用整数数组调用
newMessageArray()
,例如array(1,2,3,4,5)
,它们都会被发送。另外,您应该将变量名称(从
$array
和$element
)更改为更有意义的名称。我不知道你想做什么,所以我不确定要使用什么名称。I would create a wrapper function that accepts an array, and then call it.
This way, you can call
newMessageArray()
with an array of integers, such asarray(1,2,3,4,5)
, and they will all be sent.Also, you should change the variable names (from
$array
and$element
) to something more meaningful. I don't know what you're trying to do, so I wasn't sure what names to use.你的问题不清楚,只是猜测。
转换整数似乎有错误,请尝试
使用“intval”转换字符串不是整数的地方。
Your Question is not clear, It's only a guess work.
It seems to be error in convert integer, try
Convert where the string is not integer using 'intval'.
我相信您可能正在寻找的是如何执行此操作:
您的数据库表中有 id,对吗?并且您正在尝试将多个 id 放入一个数组中,以便该数组可以在 $apns->newMessage() 调用中使用,对吗? (我检查了来源。 .) 但是,
id
不知何故以string
的形式出现,而不是int
。因此,您可能只想确保新数组由
int
组成,如下所示:可能还有其他方法可以做到这一点,但这样,您至少知道您有该数组中的 int 变量。希望有帮助!
I believe what you may be looking for is how to do this:
You have
id
s in your database table, right? And you are trying to get multipleid
s into an array so that the array can be used in$apns->newMessage()
call, right? (I checked the source for this...) But, theid
s are somehow coming over asstring
s instead ofint
s.So, you probably want to just make sure that the new array is made up of
int
s, like this:There are probably other ways to do this, but this way, you at least know that you have int variables in that array. Hope that helps!