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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:54:46+00:00 2026-06-13T17:54:46+00:00

I have an array of the following structure: $some_array = array( array( ‘font’ =>

  • 0

I have an array of the following structure:

$some_array = array(
    array(
        'font' => 'Arial',
        'label' => 'Arial'
    ),
    array(
        'font' => 'PT+Sans:400',
        'label' => 'PT Sans'
    )
);

Let’s say that I only know that one item has ‘font’ value of ‘PT+Sans:400’ and I need to retrieve the ‘label’ value of that single item. How can I do it easier than iterating through subarrays?

  • 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-13T17:54:47+00:00Added an answer on June 13, 2026 at 5:54 pm

    Since you are already using foreach you just want other alternatives then you can consider this solutions

    Solution 1

    You can try to filter your search using array_filter

    $search = "PT+Sans:400" ;
    $array = array_filter($array,function($v)use($search){ return $v['font'] == $search;});
    var_dump($array); // returns all found array 
    

    Output

    array
      1 => 
        array
          'font' => string 'PT+Sans:400' (length=11)
          'label' => string 'PT Sans' (length=7)
    

    If you need only the label

    $find = array_shift($array); // take only the first
    print($find['label']);  // output the label 
    

    Output

    PT Sans
    

    Solution 2

    It you are not interested in return the array and all you want is just the label then you should consider array_reduce

    $search = "PT+Sans:400" ;
    $results = array_reduce($array,function($a,$b)use($search){ return $b['font'] == $search ? $b['label'] : null ; });
    print($results);
    

    Output

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

Sidebar

Related Questions

I have an array of records that is laid out in the following structure:
I have the following array structure: Array ( [0] => Array ( [configuration_id] =>
I have the following JavaScript data structure. a[] is an array with text strings
I have following array, that I need to operate by hand on bitmaps. const
I have an array that looks like the following: array = [[1, 5], [4,
Let's say I have this Hello.scala. object HelloWorld { def main(args: Array[String]) { println(Hello,
I have the following array with a structure within each array (see this jsfiddle
I have the following code with a structure array with data to make some
I have the following program. It is object oriented, having a structure 'array' (I
I have the following array of structures called test, where each field is a

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.