Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用pushWoosh类时,array_key_exists()要求参数2为数组、字符串_Php_Arrays_Class - Fatal编程技术网

Php 使用pushWoosh类时,array_key_exists()要求参数2为数组、字符串

Php 使用pushWoosh类时,array_key_exists()要求参数2为数组、字符串,php,arrays,class,Php,Arrays,Class,我在实现pushwoosh类时遇到了一些问题。我已经设置好了一切,但是我从类中得到了一个数组错误 这是我提供给该类的代码: <?php require '../core/init.php'; //get values from the clientside $sendID = $_POST['sendID']; $memID = $_POST['memID']; //get sender name $qry = $users->userdata($memID); $sendNam

我在实现pushwoosh类时遇到了一些问题。我已经设置好了一切,但是我从类中得到了一个数组错误

这是我提供给该类的代码:

<?php
require '../core/init.php';

//get values from the clientside
$sendID = $_POST['sendID'];
$memID = $_POST['memID'];

//get sender name
$qry = $users->userdata($memID);
$sendName = $qry['name'];

//get receiving token
$qry2 = $users->getTokenForPush($sendID);
$deviceToken = $qry2['token'];
//i have testet that $deviceToken actually returns the $deviceToken so thats not the problem

//this is the array that the php class requires.
$pushArray = array(
        'content'   => 'New message from ' . $sendName,
        'devices'   => $deviceToken,
);

$push->createMessage($pushArray, 'now', null);
?>

有没有一个聪明的头脑能告诉我出了什么问题

如果我理解,您正在尝试查看当前是否正在读取设备子阵列。你应该试试这个:

foreach ($pushes as $key => $push) {
    ...
    // If a list of devices is specified, add that to the push data
    if ($key == 'devices') {
        $pushData['devices'] = $push['devices'];
    }
您迭代$push,即数组'content'=>…,'devices'=>。。。。首先是$key=content,$key='devices'。

看起来createMessage函数需要一个消息数组,但您直接传递一条消息。请尝试以下方法:

$push->createMessage(array($pushArray), 'now', null);

该类需要一个数组数组;您只是提供了一个数组

你可以这样做

//this is the array that the php class requires.
$pushArrayData = array(
        'content'   => 'New message from ' . $sendName,
        'devices'   => $deviceToken,
);
$pushArray[] = $pushArrayData

您是否希望处理多条消息?这会对我的工作方式产生影响。

嗯,如果我理解你的话,我就不是舒尔。您的意思是更改pushWosh类中的代码吗?我还没有创建这个类,只是在尝试实现它。该类的文档可以在这里找到。只要你总是只发送一个,这就行了,这使得做foreach没有什么用处,尽管如果这是需要的,这是类要求的,那么就是这样。对于提示Wolfgang,这是有效的!我仍然没有在我的设备上收到任何推送通知,但错误数组消息已经消失:非常感谢。
//this is the array that the php class requires.
$pushArrayData = array(
        'content'   => 'New message from ' . $sendName,
        'devices'   => $deviceToken,
);
$pushArray[] = $pushArrayData