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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:13:09+00:00 2026-06-12T07:13:09+00:00

I have an array which contains a great deal of data, which has been

  • 0

I have an array which contains a great deal of data, which has been generated from a JSON file. Most of the data is used to populateinput elements, but some of the keys contain hidden, default values to be used for calculations later.

The array looks something like this:

[name] => 'My App'
[default_E17] => 0.009
[default_H17] => 0.0236
[default_K17] => 50
[default_P17] => 0.0118
[default_E19] => 0.03

I want to loop over all default_* keys, and output them using HTML. Essentially, I want a foreach loop, but only for the keys whose format matches default_*. Does anyone know if this is possible?

Please note that the values in the array before [default_*] keys is variable length, so I cannot easily use an array_splice().

  • 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-12T07:13:10+00:00Added an answer on June 12, 2026 at 7:13 am

    You use strpos($key, "default_") === 0 to show that it start with default_ and its not in the middle or end

    $array = array();
    $array['name'] = 'My App';
    $array['default_E17'] = "0.009";
    $array['default_H17'] = "0.0236";
    $array['default_K17'] = "50";
    $array['default_P17'] = "0.0118";
    $array['default_E19'] = "0.03";
    $array['E19_default_test'] = "1.03";
    
    
    echo "<pre>";
    

    * You can use foreach *

    $list = array();
    foreach ( $array as $key => $value ) {
        if (strpos($key, "default_") === 0) {
            $list[$key] = $value;
        }
    }
    
    var_dump($list);
    

    You can also use array_flip with array_filter

    $array = array_flip(array_filter(array_flip($array),function($var) { return (strpos($var, "default_") === 0);}));
    var_dump($array);
    

    You can also use FilterIterator

    class RemoveDefaultIterator extends FilterIterator {
        public function accept() {
            return (strpos($this->key(), "default_") === 0);
        }
    }
    
    $list = new RemoveDefaultIterator(new ArrayIterator($array));
    var_dump(iterator_to_array($list));
    

    They would all Output

    array
      'default_E17' => string '0.009' (length=5)
      'default_H17' => string '0.0236' (length=6)
      'default_K17' => string '50' (length=2)
      'default_P17' => string '0.0118' (length=6)
      'default_E19' => string '0.03' (length=4)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which contains different blocks of data and i have to
I have an array which contains serialized data similar to the example below. Array
I have Javascript array which contains User object. I have created this array from
I have an array which contains many keys/values that are generated dynamically, so I
I have an array which contains a set of information from a database, but
I have an array which contains 12 numbers and I want to save this
I have an array which contains a set of UIImage in byte forms. --My
I have an array which contains another array Would I notate it this way?
I have an array which contains around 50-200 hyperlinks. How can I pass this
I have an array which contains sets of three similar named items; however, sometimes

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.