不能使数组发挥作用


cant make array to function

首先为我的英语道歉函数

所使用的数组
  1. 上传文本文件,每一行都将成为数组

    中的元素
    $fh = fopen("upload/".'1.txt','r');
    $conn = array();
    while ($line = fgets($fh)) {
        $conn[] = $line;
    }
    fclose($fh);
    $wbs->SendBulk($conn, "hello world");
    
  2. Go To Function

    public function SendBulk($targets, $message)
    {
        echo "Sending " . count($targets) . " bulk messages...<br />";
        foreach($targets as $target)
        {
            $this->wa->sendPresenceSubscription($target);
            $this->wa->pollMessages();
            $this->wa->sendMessageComposing($target);
            sleep(55);
            $this->wa->pollMessages();
            $this->wa->sendMessagePaused($target);
            static::$sendLock = true;
            echo "Sending message from " . $this->username . " to $target... ";
            $this->wa->sendMessage($target, $message); // Orginal
            while(static::$sendLock)
            {
                //wait for server receipt
                sleep(55);
            }
        }
    

我的问题如果我有在文本文件2或更多的元素在数组将为最后一个元素发送消息吗但是如果我创建这样的数组

$conn= array("565684898", "484849815", "484897987", "515498798");

它适用于所有元素请帮助

fgets()返回的字符串包括每行结束的换行符。使用rtrim()将其移除:

$conn[] = rtrim($line);

您还可以将读取文件的整个代码替换为:

$conn = file('upload/1.txt', FILE_IGNORE_NEW_LINES)