Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:18:30+00:00 2026-06-16T00:18:30+00:00

I have a slice of PHP code that’s throwing an error; Notice: Array to

  • 0

I have a slice of PHP code that’s throwing an error;

Notice: Array to string conversion.

It is because for some reason $deviceToken is an array when it should be a string.

I don’t why PHP thinks it is an array. When I print results array of my mysqli query, it shows an array in an array, and because of that, it thinks $deviceToken is an array. I only want one array, $rows and $deviceToken to be the value variables of the array. Because of this, later in the code where $deviceToken is read in the binary, its throwing another error because apparently its an array, not a string. See below for code:

// Create an array of units assigned to call
$unitsarray = explode(",", $units);

for ($i = 0; $i < count($unitsarray); $i++){

    echo "Units row $i = $unitsarray[$i] <br />";

    $result = $mysqli->query("SELECT devicetoken FROM `department devices` WHERE unit LIKE $unitsarray[$i]");

    while($row = $result->fetch_assoc()) {
        $rows[] = $row;
    }

    echo "ResultsArray = ";
    print_r($rows);

    // Loop APNS for each device token in $devicetoken array
    foreach ($rows as $deviceToken)
    {    
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack("H*", $deviceToken) . pack('n', strlen($payload)) . $payload;

    // Send it to the server
    $result2 = fwrite($fp, $msg, strlen($msg));

    // Create APNS operation output
    if (!$result2)
        echo 'Failed message'.PHP_EOL;
    else
        echo "<b>Successful message sent:</b>&nbsp;&nbsp; $call - $location - $station - $units to device(s):&nbsp;&nbsp;'$deviceToken </br>".PHP_EOL;
    }
}

Results array output looks like this:

ResultsArray = Array (
    [0] => Array (
        [devicetoken] => 773f5436825a7115417d3d1e036da20e806efeef547b7c3fe4da724d97c01b30
    )
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:18:31+00:00Added an answer on June 16, 2026 at 12:18 am

    $deviceToken is an array, you want the key devicetoken from that array, not the array itself.

    foreach ($rows as $key => $row)
    {    
        $deviceToken = $row['devicetoken'];  
        // Build the binary notification
        $msg = chr(0) . pack('n', 32) . pack("H*", $deviceToken) . pack('n', strlen($payload)) . $payload;
    
        // Send it to the server
        $result2 = fwrite($fp, $msg, strlen($msg));
    
        // Create APNS operation output
        if (!$result2)
            echo 'Failed message'.PHP_EOL;
        else
            echo "<b>Successful message sent:</b>&nbsp;&nbsp; $call - $location - $station - $units to device(s):&nbsp;&nbsp;'$deviceToken </br>".PHP_EOL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have php function that parses a xml url and gives me an array.this
ok this is some crazy jquery code that I have here. what its doing
I have a snippet of JQuery code that do some bar scrolling. Since I
I have one list that I want to take a slice of, reverse that
I have a std::vector. I want to create iterators representing a slice of that
I'm looking to slice a two dimensional array in C#. I have double[2,2] prices
I have tried the following code in single.php file in wordpress. I used these
I have this code that creates the navigation for a slideshow. It works just
I have two pieces of code that I need to use together. I am
Possible Duplicate: php split array into smaller even arrays How can I slice an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.