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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:05:26+00:00 2026-06-08T00:05:26+00:00

I am extracting variables from an array and works fine , but just happens

  • 0

I am extracting variables from an array and works fine , but just happens that in same file I have news items from different category with array that has same key names so they get mixed up and first set loaded takes over, what I need is a prefix or suffix for the variable so I can differentiate one from another

function get_extra_fields($item){
    $item->extra_fields = K2ModelItem::getItemExtraFields($item->extra_fields);
    foreach ( $item->extra_fields as $key => $extraField ){

        $getkey  = strtolower($extraField->name);
        $getkey  = str_replace(' ', '', $getkey);
        global $$getkey;
        $$getkey = $extraField->value;
    }

}

and it is called within foreach for 3 different categories

foreach($get_gcat1 as $row => $item){
   get_extra_fields($item);
  echo $newstitle;
}

foreach($get_cat2 as $row => $item){
   get_extra_fields($item);
   echo $newstitle;
}

foreach($get_cat3 as $row => $item){
   get_extra_fields($item);
   echo $newstitle;
}

any help is appreciated. thank you!

  • 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-08T00:05:28+00:00Added an answer on June 8, 2026 at 12:05 am

    Strange way for creating global variables, but here is something that may do what you want:

    function get_extra_fields($item, $prefix){
        $item->extra_fields = K2ModelItem::getItemExtraFields($item->extra_fields);
        foreach ( $item->extra_fields as $key => $extraField ){
            $getkey  = strtolower($extraField->name);
            $getkey  = str_replace(' ', '', $getkey);
            $GLOBALS[$prefix.$getkey] = $extraField->value;
        }
    }
    
    
    foreach($get_gcat1 as $row => $item){
      get_extra_fields($item, 'cat1_');
      echo $cat1_newstitle;
    }
    
    foreach($get_cat2 as $row => $item){
       get_extra_fields($item, 'cat2_');
       echo $cat2_newstitle;
    }
    
    foreach($get_cat3 as $row => $item){
       get_extra_fields($item, 'cat3_');
       echo $cat3_newstitle;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On extracting some html from a web page, I have some elements containing text
I'm extracting some information from an XML file, and I want to perform some
C# : I have a string that comes from a webpage's sourcecode: <script type=text/javascript>
In my PHP page, I am extracting a bunch of variables from the URL,
I am trying to obtain embeded code through extracting variables from Youtube video URLs.
struggle extracting necessary data from this complex json stored inside php variable. Via php
I'm struggle extracting necessary data from this json stored inside php variable. Not yet
I'm extracting the min from a vector. Say vector = [0, inf, inf, inf];
I'm working on extracting data from a SQL Server database with a latin_1 character
I am extracting a column of data from a range of filenames. All my

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.