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

  • Home
  • SEARCH
  • 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 8715353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:49:25+00:00 2026-06-13T05:49:25+00:00

I have written a long script that does exactly what I need, but now

  • 0

I have written a long script that does exactly what I need, but now I am find out the usefulness of functions so I can use them in other scripts.

My script works perfectly the way I originally wrote it, and also works perfectly with the way I implemented the function I created.

As I am brand new to writing functions and I have never seen one implemented the way I have done, I don’t know if it is good form or not.

Original Way

foreach($get_prefixes as $prefix) {
    if($prefix['type'] == 'pre') {
        $sql  = "SHOW COLUMNS FROM `$prefix[table]` LIKE 'sku_%' ";
        $sku_cols = $objDb->query($sql);
        foreach($sku_cols as $col) {
            echo $col['Field'] . '<br>';
        }
    }
}

And then there is the way I did it with the created function. Again it works perfectly, but is there is a "proper" way to do this?

function getSku_($table) {
    global $objDb;
    $sql  = "SHOW COLUMNS FROM `$table` LIKE 'sku_%' ";
    $sku_cols = $objDb->query($sql);
    return $sku_cols;
}

foreach($get_prefixes as $prefix) {
    if($prefix['type'] == 'pre') {
        foreach(getSku_($prefix['table']) as $col) {
            echo $col['Field'] . '<br>';
        }
    }
}
  • 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-13T05:49:26+00:00Added an answer on June 13, 2026 at 5:49 am

    I don’t see anything wrong with the function, except for its naming. It’s not incorrect, just that I understand its convention is to follow naming as abc_pqr or abcPqr or _abcPqr (for private functions).

    Edit: I also don’t see $get_prefixes defined anywhere, before using in the foreach, in the function. Where is it coming from?

    foreach($get_prefixes as $prefix) { //This line
    

    If the functions differ in just the query, "sku" and "sku " then you don’t even need two functions, just use an OR in the query (preferred) or maybe two queries, if you want the two result sets to be separate.

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

Sidebar

Related Questions

I have written a script image.php that is quite long, but I've just copied
I have a script written long ago by a freelancer that's worked fine until
I have written a framework that does calculations that take a long time to
I Have a program written in VB6 that reads a long text file and
I have a binary file, that was written in C, which contains a long
I have a SQL script that will insert a long string into a table.
I have a script, written in PHP that uses the AWS Dynamo PHP API.
I have a huge array that is written literally thanks to a script. It
I have written a ruby script that then calls another ruby script. The callee
I have written a CGI script that creates an image dynamically using GET data.

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.