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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:44:55+00:00 2026-05-31T00:44:55+00:00

I noticed that some functions in PHP use flags as arguments. What makes them

  • 0

I noticed that some functions in PHP use flags as arguments. What makes them unique instead of plain string arguments? I’m asking since I want to use them on my own custom functions but am curious as to what the process is for doing so.

Edit: TO summarize, when is it best to create a custom function with flags and when is it not?

  • 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-05-31T00:44:56+00:00Added an answer on May 31, 2026 at 12:44 am

    They are just constants which map to a number, e.g. SORT_NUMERIC (a constant used by sorting functions) is the integer 1.

    Check out the examples for json_encode().

    As you can see, each flag is 2n. This way, | can be used to specify multiple flags.

    For example, suppose you want to use the flag JSON_FORCE_OBJECT (16 or 00010000) and JSON_PRETTY_PRINT (128 or 10000000).

    The bitwise operator OR (|) will turn the bit on if either operand’s bit is on…

    JSON_FORCE_OBJECT | JSON_PRETTY_PRINT
    

    …is internally….

    00010000 | 1000000
    

    …which is…

    10010000
    

    You can check it with…

    var_dump(base_convert(JSON_PRETTY_PRINT | JSON_FORCE_OBJECT, 10, 2));
    // string(8) "10010000"
    

    CodePad.

    This is how both flags can be set with bitwise operators.

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

Sidebar

Related Questions

While reading cocoa tutorials i've noticed that some of the tutorials use AppDelegate and
I have noticed that PHP and JavaScript treat octal and hexadecimal numbers with some
I've noticed that PHP's current() and key() array functions ( like other array-pointer functions
Exception handling in php ... I have noticed some quirks that seem to make
I noticed that some enumerations have None as a enumeration member. For example what
I noticed that some stylesheets have something like this: body { font-size: 62.5%/1.2em; }
I've noticed that some sites (usually banks) suppress the ability to paste text into
I have noticed that some apps like Safari and Mail show a loading indicator
I've noticed that on some websites (including SO) the link to the CSS will
I've playing around with linux and noticed that for some mysterious reason commands like

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.