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 8849875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:46:03+00:00 2026-06-14T12:46:03+00:00

I am a little rusty in PHP after several years without programming with this

  • 0

I am a little rusty in PHP after several years without programming with this language.

I am fetching data from an array in mySQL using PHP.

My problem is that at some point I fetch data from a table, using this:

$myArray = mysql_fetch_array( $data ); 

but at some point, the data base may be empty, so $myArray will be null or contain no elements.

Then I have to check if a particular string that is generated on-the-fly is on $myArray. If it is, another string must be generated and verified if it already exists on $myArray.

$myString = generateString();
if (in_array($myString, $myArray)) {
    $myString = generateString();
}

this code gives me this error:

Warning: in_array() [function.in-array]: Wrong datatype for second argument

To prevent in_array from running when $myArray is empty I did this:

if (count($myArray) > 0) {
    if (in_array($myString, $myArray)) {
        $myString = generateString();
    }
}

but count is giving me 1 when the array is empty (?)…

How do I solve that?

just another question: $myString is being modified inside the IF that is already testing it. Is this possible in PHP?

  • 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-14T12:46:04+00:00Added an answer on June 14, 2026 at 12:46 pm

    Well, if your query failed, you’ll have… wait for it… no array!

    So that in_array call would give you a warning about $myArray not being an array (but false).

    You need to check your query for errors, and better yet:

    Please, don’t use mysql_* functions in new code. They are no longer maintained and the deprecation process has begun on it. See the red box? Learn about prepared statements instead, and use PDO or MySQLi – this article will help you decide which. If you choose PDO, here is a good tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My php is a little rusty but this is boggling my mind right now.
a little rusty from my Scheme days, I'd like to take 2 lists: one
My windbg skills are a little rusty, so forgive me if this is obvious.
I'm a little lot rusty with my SQL and this is driving me nuts.
My XPath is a little bit rusty... Let's say I have this simple XML
I am a little rusty with css and I am stuck on this, what
not sure if this is possible without having to go through several passes, but
After a break from Python(and I knew very little then!) I'm coming back to
My Access programming is a little rusty, & I've never worked with Excel files
I haven't wrote PHP GET requests in a while. So I'm a little rusty.

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.