Click here to Skip to main content
15,172,251 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Master Detail CRUD using blazor Pin
sanket16415-Apr-21 9:09
Membersanket16415-Apr-21 9:09 
GeneralRe: Master Detail CRUD using blazor Pin
Mycroft Holmes15-Apr-21 14:52
professionalMycroft Holmes15-Apr-21 14:52 
QuestionDo events like slider and drag and drop need to be well known? Pin
Oyee 202129-Mar-21 20:31
MemberOyee 202129-Mar-21 20:31 
AnswerModeration Pin
Nelek29-Mar-21 20:32
protectorNelek29-Mar-21 20:32 
AnswerRe: Do events like slider and drag and drop need to be well known? Pin
Richard Deeming29-Mar-21 22:42
mveRichard Deeming29-Mar-21 22:42 
QuestionHTML Rotate results in messed up and unresponsive design. Pin
Resource Link26-Mar-21 8:19
MemberResource Link26-Mar-21 8:19 
QuestionRefresh token API development and documentation Pin
kyclk1125-Mar-21 20:15
Memberkyclk1125-Mar-21 20:15 
QuestionPHP7, how to create a json array of keyvalues from an object Pin
jkirkerx25-Mar-21 11:57
professionaljkirkerx25-Mar-21 11:57 
I've been trying for a couple of hours. So I have these models or object classes, one called KeyValues and KeyValue. I make a database call, and create the KeyValues object with a collection of KeyValue. This is working pretty good in just PHP V7.4.14, and I'm happy with it.

So now, I made an API, that creates a JSON array of KeyValues, and some plain Javascript to call Fetch and get the list from my hacked together PHP file. I can't figure out how to package the JSON from my object in PHP.

I wanted to use the example below, forJSON(), and was thinking that it can take an object, and package it in one line of code, but I have no clue if I fabricated it right, and how to call it. I would that it belongs in the InteratorIterator to process the whole object.

The last example is me trying just piece something together from information on the internet. I had a couple that worked, but the format was wrong, so this is just concept code of what I'm trying to do.

I just need help in filling in a couple of blanks I'm missing in the concept of how it works.
class KeyValues extends IteratorIterator {

<pre>
public function __construct(KeyValues ...$keyValues)
{
    parent::__construct(new ArrayIterator($keyValues));
}
class KeyValue {

    var $key;
    var $value;
    var $keyValues;

    public function __construct()
    {

    }

    public function getKey() { return $this->key; }
    public function setKey($key) { $this->key = $key; }

    public function getValue() { return $this->value; }
    public function setValue($value) { $this->value = $value; }

    public function forJSON(): array
    {
        foreach ($this->keyValues as $keyValue) $keyValues[] = $keyValue->forJSON();
        return array(
            'key' => $this->getKey(),
            'value' => $this->getValue()
        );

    }

}
$jsonRaw = [];
foreach ($keyValues as $keyValue) {
    $jsonArray = $keyValue->getKey() => $keyValue->getValue();
    array_push($jsonRaw, $jsonArray);
}
echo json_encode($jsonRaw, JSON_PRETTY_PRINT);
exit();



If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: PHP7, how to create a json array of keyvalues from an object Pin
jkirkerx26-Mar-21 12:18
professionaljkirkerx26-Mar-21 12:18 
QuestionHi, can someone help me with file-upload feature for my Angular app? Pin
kyclk1117-Mar-21 4:41
Memberkyclk1117-Mar-21 4:41 
AnswerRe: Hi, can someone help me with file-upload feature for my Angular app? Pin
jkirkerx25-Mar-21 12:02
professionaljkirkerx25-Mar-21 12:02 
QuestionReduce Javascript Pin
Member 1497619910-Mar-21 15:12
MemberMember 1497619910-Mar-21 15:12 
AnswerRe: Reduce Javascript Pin
Richard Deeming10-Mar-21 22:34
mveRichard Deeming10-Mar-21 22:34 
GeneralRe: Reduce Javascript Pin
Member 1497619910-Mar-21 22:41
MemberMember 1497619910-Mar-21 22:41 
GeneralRe: Reduce Javascript Pin
Richard Deeming10-Mar-21 22:46
mveRichard Deeming10-Mar-21 22:46 
GeneralRe: Reduce Javascript Pin
Member 1497619910-Mar-21 23:04
MemberMember 1497619910-Mar-21 23:04 
GeneralRe: Reduce Javascript Pin
Richard Deeming10-Mar-21 23:18
mveRichard Deeming10-Mar-21 23:18 
GeneralRe: Reduce Javascript Pin
Member 1497619911-Mar-21 0:01
MemberMember 1497619911-Mar-21 0:01 
QuestionHI can someone help me with my responsive gallery project? Pin
Florina Catalina10-Mar-21 5:38
MemberFlorina Catalina10-Mar-21 5:38 
AnswerRe: HI can someone help me with my responsive gallery project? Pin
Richard MacCutchan10-Mar-21 23:23
mveRichard MacCutchan10-Mar-21 23:23 
GeneralRe: HI can someone help me with my responsive gallery project? Pin
Florina Catalina12-Mar-21 7:24
MemberFlorina Catalina12-Mar-21 7:24 
GeneralRe: HI can someone help me with my responsive gallery project? Pin
Richard MacCutchan12-Mar-21 7:42
mveRichard MacCutchan12-Mar-21 7:42 
AnswerRe: HI can someone help me with my responsive gallery project? Pin
NotTodayYo12-Mar-21 8:15
MemberNotTodayYo12-Mar-21 8:15 
AnswerRe: HI can someone help me with my responsive gallery project? Pin
Member 1529865622-Jul-21 22:56
MemberMember 1529865622-Jul-21 22:56 
QuestionHello, i need some help for a project with css and html Pin
Florina Catalina10-Mar-21 5:38
MemberFlorina Catalina10-Mar-21 5:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.