Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array keys with dots not supported #14

Closed
llagerlof opened this issue Jul 10, 2024 · 2 comments
Closed

Array keys with dots not supported #14

llagerlof opened this issue Jul 10, 2024 · 2 comments
Labels
Q&A Questions raised by users (We will reply in the issue and then we can close it)

Comments

@llagerlof
Copy link

Just doing some stress testing. I tried the code below, but don't work in that scenarios.

<?php

require_once "./vendor/autoload.php";

use HiFolks\DataType\Block;

$arr = [
    'matrix' => [
        'main.actor' => 'Keanu Reeves',
        'imdb' => 8.7
    ],
    'independence_day' => [
        'main.actor' => 'Will Smith',
        'imdb' => 7
    ],
    'The.Abyss' => [
        'main.actor' => 'Ed Harris',
        'imdb' => 7.5
    ]
];

$movies = Block::make($arr);

$a = $movies->get('matrix.main.actor');

print_r($a);

$b = $movies->get('The.Abyss.imdb');

print_r($b);

$c = $movies->get('The.Abyss.main.actor'); 

print_r($c);

Maybe something like this could solve this issue? I don't know.

$a = $movies->get('matrix."main.actor"');
@roberto-butti
Copy link
Contributor

Hi @llagerlof thank you for testing the library.
To avoid conflict with the chars in the keys and the char used for determining the nested level, I introduced the charNestedKey parameter. By default, is a dot ., but you can change it in the case you need it.
I don't know if you already took a look at that parameter:

$a = $movies->get(
    'matrix#main.actor',
    charNestedKey: '#'
);

Let me know if it can help.

@roberto-butti roberto-butti added the Q&A Questions raised by users (We will reply in the issue and then we can close it) label Jul 10, 2024
@roberto-butti
Copy link
Contributor

I'm going to close this issue because I think the charNestedKey is the solution.
If you have additional questions feel free to open new issues.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Q&A Questions raised by users (We will reply in the issue and then we can close it)
Projects
None yet
Development

No branches or pull requests

2 participants