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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:22:54+00:00 2026-06-04T07:22:54+00:00

Not very strong in PHP so here is my question: I am building a

  • 0

Not very strong in PHP so here is my question:

I am building a simple array to return as json, populating it with data from another array.
The $eventarray may have the index gas or may not so I need to check for existing gas index and if it exist get the value if not populate with a default value.

How would I do that the most optimal way?

Again not that strong in PHP.

Here is the array:

 $somearr = array(
       "actiontaken"=>sprintf("%s", $eventarray['desc']),
        "actionname" =>sprintf("%s", $eventarray['name']),
        "type" =>sprintf("%s", $eventarray['type']),
        "subtype" =>sprintf("%s", $eventarray['name']),
        "min" =>sprintf("%s", $eventarray['min']),
        "gas" =>sprintf("%s", $eventarray['gas']),
        "playerId"=>$value['p'],
        "name" =>$value2['name'],
        "race" =>$value2['race']
);
  • 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-04T07:22:55+00:00Added an answer on June 4, 2026 at 7:22 am

    You can use isset() to check if the element exists (and is not null):

    isset($eventarray['gas']) ? $eventarray['gas'] : 'defaultvalue'
    

    Note: In case null is a possible value where you do not want the default value to be used you cannot use isset but have to use array_key_exists($eventarray, 'gas') instead.

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

Sidebar

Related Questions

I've got this bit of php here that is very sluggish. Not millisecond sluggish,
Possible Duplicate: String comparison in Objective-C I realize that the question is not very
I'm not very good when it comes to arrays so here's probably something very
Here is my problem. I have a ticket-tracking system that is not very 'user
Since many PHP-related questions are very basic here, I'd propose to prepare a collection
I'm new to json decoding with php. here's my situation. I need to grab
Here's what's NOT working for me: <?php $string = 'I have a dog and
Since the SOAP manual on php.net is not very noob friendly and I could
This question: Best way to return status flag and message from a method in
I'm not very strong in HTML, and each time I have some encoding problems.

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.