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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:46:42+00:00 2026-06-02T18:46:42+00:00

function test($matches) { $fx = ”; if(strpos($matches[0],http://)===false) { $fx = http://; } elseif(strpos($matches[0],http:/)===false) {

  • 0
function test($matches)
{
    $fx = '';
    if(strpos($matches[0],"http://")===false)
    {
        $fx = "http://";
    }
    elseif(strpos($matches[0],"http:/")===false)
    {
        $fx = "http:/";
    }
    elseif(strpos($matches[0],"http:")===false)
    {
        $fx = "http:";
    }
    elseif(strpos($matches[0],"http")===false)
    {
        $fx = "http";
    }
    return $fx.$matches[0];
}

or

function test($matches)
{
    if(strpos($matches[0],"http://")===false)
    {
        return  "http://".$matches[0];
    }
    elseif(strpos($matches[0],"http:/")===false)
    {
        return "http:/".$matches[0];
    }
    elseif(strpos($matches[0],"http:")===false)
    {
        return "http:".$matches[0];
    }
    elseif(strpos($matches[0],"http")===false)
    {
        return "http".$matches[0];
    }
}

I’m trying to write my scripts to them use less memory as possible, but idk sometimes the code look ugly, in my opnion the first script look more pretty and organized, but i think it use more memory of server.

thanks.

  • 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-02T18:46:44+00:00Added an answer on June 2, 2026 at 6:46 pm

    As far as which one will use less memory, I would think they are equivalent (both at their worst case).

    However, as for their run times, the second one will finish executing a fraction of a nano-second faster than the first because, it will return as soon as it finds one matching condition. Over all the difference in Big-O is constant which we all know doesn’t make a difference: O(3n) verses O(n) at the best case, and O(3n) verse O(3n) at worst case (dependant on the size of $match[0]). But all this is deeply dependant on the complexity of the strpos() function.

    For readability, they are also equilavently written and structured.

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

Sidebar

Related Questions

I am trying to write a function to transform a string literal in Delphi/pascal
I'm using javascript's inbuilt .test() function to test whether a string or regex matches.
function replaceContent($matches = array()){ if ($matches[1] == nlist){ // do stuff return replace value;
Overview I am trying to find the jQuery function that matches a selection attribute
function test(){ if(true){ var a = 5; } alert(a); } test(); I keep getting
public function test(){ $data = ORM::factory('testdata')->find_all(); Table::factory() ->set_body_data($data) ->set_row_titles('id') ->set_column_titles(Table::AUTO) ->set_callback('format_row', 'row') ->render(true); $this->template->title
suppose I have a function: function test(){} test.prototype.method01=function(){ //do something } test.prototype.method02=function(){ //how can
I have just come across this code: function test(){ //... if ( $profilerule ==
abstract class base { abstract public function test(); public function run() { self::test(); }
I want to create SQL function with JDBC CREATE OR REPLACE FUNCTION TEST.TO_STRING( nt_in

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.