0

I have the following array in PHP:

enter image description here

What I'd like to do is to bring back the value of:

[size:PhpOffice\PhpWord\Style\Font:private]

to a variable (in this case 20).

I tried to do the following:

foreach($array as $array2){
    if(isset($array2->size)){
        echo $array2->size;
    }
}

But, it didn't work.

How do I solve this problem?

Emma
  • 27,428
  • 11
  • 44
  • 69
orhs
  • 1
  • 1
  • 1
    check this it may help you https://www.php.net/manual/fr/function.array-key-exists.php – A.Marwan Apr 24 '19 at 15:22
  • 1
    It looks as though it's an object rather than an array and `:private` means you will have to find a method to access it (or hack the object). – Nigel Ren Apr 24 '19 at 15:26
  • Possible duplicate of [What's the difference between isset() and array\_key\_exists()?](https://stackoverflow.com/questions/3210935/whats-the-difference-between-isset-and-array-key-exists) – Amin.MasterkinG Apr 24 '19 at 16:27
  • It seems from your snippet that the `size` field you want to access is inside `fontStyle`, so wouldn't you have to access it as `$array->fontStyle->size` instead? – slashCoder Apr 24 '19 at 16:43

1 Answers1

0
foreach ($array as $array2) {
    // access fontStyle via getter
    $fontStyle = $array2->getFontStyle();
    // access private property via getter
    echo $fontStyle->getSize();
}

Other getters for PhpOffice\PhpWord\Style\Font object you can find in https://github.com/PHPOffice/PHPWord/blob/develop/src/PhpWord/Style/Font.php (yes, sometimes you have to look at source code of a library you're using).

u_mulder
  • 54,101
  • 5
  • 48
  • 64